Skip to content

Commit 5bc8e0f

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

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ PHPUnit运行失败
106106

107107
在编写测试用例之前,先编写一个应用类 Email,我们在项目根目录下创建一个 app 目录,并将 Email.php 保存在该目录下,然后编写 Email 类代码如下:
108108

109+
```
109110
<?php
110111
declare(strict_types=1);
111112
@@ -143,13 +144,18 @@ final class Email
143144
}
144145
}
145146
}
147+
```
148+
146149
然后,我们在 composer.json 中配置 autoload 选项通过 PSR-4 规则加载 app 目录下的类文件:
147150

151+
```
148152
"autoload": {
149153
"psr-4": {
150154
"App\\": "app/"
151155
}
152156
},
157+
```
158+
153159
以便能够通过命名空间加载到 app 目录下的类。配置完成后,运行 composer dump-auto 命令重新生成自动加载文件以便 Email 类可以被正常加载到。
154160

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

0 commit comments

Comments
 (0)