Windows 下使用 phpunit 执行的时候一直提示报错,麻烦指点一二

这是我的代码

namespace Tests\Feature;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Tests\TestCase;
class TbTokenTest extends TestCase
{
    public function testExample()
    {
        $data = '{"my_account":"ihouxin"}';
        $response = $this->json('POST', '/hs/save_friend_message', ['data'=>$data]);
        $response->dumpHeaders();
        $response->dump();
        $response->assertJson(['code'=>200]);
    }
}

我使用的windows下的"phpunit.phar"工具。
在cmd命令行里面运行“phpunit”的情况下,提示报错
下面是错误截图

There was 1 error:

1) Tests\Feature\ExampleTest::testBasicTest
ErrorException: Declaration of Illuminate\Foundation\Testing\Assert::assertArraySubset($subset, $array, bool $checkForObjectIdentity = false, string $message = ''): void should be compatible with PHPUnit\Framework\Assert::assertArraySubset($subset, $array, $strict = false, $message = '')

G:\WWW\wechat\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Assert.php:42
G:\WWW\wechat\vendor\laravel\framework\src\Illuminate\Foundation\Testing\TestResponse.php:164
G:\WWW\wechat\tests\Feature\ExampleTest.php:19

ERRORS!
Tests: 3, Assertions: 2, Errors: 1.

头部和内容是可以正常打印的 。就是最后会这样报错 ,是不是哪里配置错了?

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

看错误提示,是 laravel 中继承了 phpunit 中的方法,但是方法的参数却不同。。。

所以推测,,phpunit 版本跟 laravel 所需的版本不匹配,,,而且是低于 laravel 所需的版本,,,更新你那个 phpunit.phar 应该可以解决,,,

5年前 评论
讨论数量: 2

看错误提示,是 laravel 中继承了 phpunit 中的方法,但是方法的参数却不同。。。

所以推测,,phpunit 版本跟 laravel 所需的版本不匹配,,,而且是低于 laravel 所需的版本,,,更新你那个 phpunit.phar 应该可以解决,,,

5年前 评论

@largezhou
是的,你说的对,确实是这样的。
我的laravel版本是v6.2.0。
现在换了phpunit-7.0.3.phar,这版本就可以正常使用了。多谢指导。

之前试过了,phpunit-6.2.4.phar,phpunit-6.5.3.phar,这两个都是不行。因为他的官方文档只是提供了这两个链接,我就以为应该不是这个问题。后来我去了github上下载了最新的phpunit-7.0.3就正常了。

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!