将phpunit与Laravel和Spatial一起使用

将phpunit与Laravel和Spatial一起使用,laravel,phpunit,spatie,Laravel,Phpunit,Spatie,我尝试将phpunit与Laravel和Spatial一起使用,但我有一个问题 我有这个测试: public function testBasicTest() { $user = User::where('id', 2)->first(); $response = $this->actingAs($user, 'api')->json('POST', '/providersList', [ 'database

我尝试将phpunit与Laravel和Spatial一起使用,但我有一个问题

我有这个测试:

 public function testBasicTest()
    {

        $user = User::where('id', 2)->first();

        $response = $this->actingAs($user, 'api')->json('POST', '/providersList', [
            'database' => 'test'
        ]);

        $response->assertStatus(200);   
    }
但我有个错误

  Expected status code 200 but received 401. Failed asserting that 200 is identical to 401.
我在web.php中有这个

Route::group(['middleware' => ['auth:api','role:Admin']], function() {

    Route::post('/providersList', 'ProviderController@index');

});

这是执行测试时的一个常见问题,我可以向您保证,此错误的原因是由于401 HTTP错误代码的身份验证,请检查代理用户是否具有admin角色要获得更好的错误输出,请将其添加到测试函数的顶部

 $this->withoutExceptionHandling();

它应该能更好地了解问题所在。

我通过
dd($user->hasRole('Admin'))检查返回truetry使用postman并手动点击该api,您应该可以看到错误的输出