Skip to content

Commit 17c8a73

Browse files
committed
docs: 基于 phpunit
1 parent 5bc8e0f commit 17c8a73

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

laravel/readme/25. 2019-06-24- 从基于 PHPUnit 编写单元测试开始.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ final class Email
160160

161161
接下来,我们在 tests/Unit 目录下创建一个新的测试用例 EmailTest.php,用来测试刚刚编写的 Email 类:
162162

163+
```
163164
<?php
164165
namespace Unit\Test;
165166
use PHPUnit\Framework\TestCase;
@@ -189,6 +190,8 @@ class EmailTest extends TestCase
189190
);
190191
}
191192
}
193+
```
194+
192195
在上述代码中,第一个测试方法使用了基类提供的断言方法 assertInstanceOf 判断 Email::fromString 方法返回的是否是 Email 实例;第二个测试方法中使用了 expectException 判断传入无效的邮件地址是否抛出指定异常;第三个测试方法则使用 assertEquals 判断 Email::fromString 打印结果是否与给定字符串相等。
193196

194197
下面我们来运行单元测试:

0 commit comments

Comments
 (0)