接上文,好不容易配置好phpunit 一运行命令:
phpunit tests/feature/exampletest
报错:
ErrorException: Declaration of Illuminate\Testing\Assert::assertArraySubset($subset, $array, bool $checkForIdentity = false, string $msg = ‘‘): void should be compatible with PHPUnit\Framework\Assert::assertArraySubset($subset, $array, $strict = false, $message = ‘‘)
解决办法:推测是因为 phpunit 版本跟 laravel 所需的版本不匹配,而且是低于 laravel 所需的版本,更新 phpunit.phar 可以解决
查看phpunit版本命令:
$ phpunit --version PHPUnit x.y.z by Sebastian Bergmann and contributors.
重新下载最新版本的phpunit 8.5.8.phar,复制到之前安装phpunit的目录覆盖
之后重新输入命令:
$ phpunit --version PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
成功了,现在我们再来单元测试:
$ phpunit tests/feature/exampletest PHPUnit 8.5.8 by Sebastian Bergmann and contributors. Warning: Invocation with class name is deprecated . 1 / 1 (100%) Time: 213 ms, Memory: 24.00 MB OK (1 test, 1 assertion)
搞定,收工!