Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/287.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未经授权的用户在使用phpunit测试时返回状态500而不是401_Php_Laravel_Phpunit_Laravel Passport - Fatal编程技术网

未经授权的用户在使用phpunit测试时返回状态500而不是401

未经授权的用户在使用phpunit测试时返回状态500而不是401,php,laravel,phpunit,laravel-passport,Php,Laravel,Phpunit,Laravel Passport,我正在与buddy.works合作,以持续集成我的项目。问题是,我的phpunit测试在本地计算机上通过,但在buddy works管道上失败 我已经尝试了两天多的谷歌搜索和阅读,虽然我发现了许多类似的问题,但我还没有找到一个解决方案,甚至可以为我指明正确的方向 public function test\u orders\u route\u unauthenticated\u user(){ $data=[ 'orderID'=>'001241', “sku”=>“123456”, “数量”=>

我正在与buddy.works合作,以持续集成我的项目。问题是,我的phpunit测试在本地计算机上通过,但在buddy works管道上失败

我已经尝试了两天多的谷歌搜索和阅读,虽然我发现了许多类似的问题,但我还没有找到一个解决方案,甚至可以为我指明正确的方向

public function test\u orders\u route\u unauthenticated\u user(){
$data=[
'orderID'=>'001241',
“sku”=>“123456”,
“数量”=>9,
“pricePerUnit”=>78,
'priceTotal'=>702,
];
$this->json('POST','api/orders',[$data])->assertStatus(401);
}
测试失败,状态代码是500,而不是401,我不知道是什么原因造成的

编辑:
Laravel 5.8.17是与之集成的php单元,在buddy works上运行之前,它一直按预期工作。

在测试我的Laravel 8 api时遇到了同样的问题。 我必须发送标题和我的请求

public function testGetUsersWithoutAuthentication()
{
    $response = $this->withHeaders(['Accept' => 'application/json',])->get('api/users');
    $response->assertStatus(401);
}

在测试我的Laravel8API时遇到了同样的问题。 我必须发送标题和我的请求

public function testGetUsersWithoutAuthentication()
{
    $response = $this->withHeaders(['Accept' => 'application/json',])->get('api/users');
    $response->assertStatus(401);
}

你的日志怎么说?一个500应该留下一个entry500意味着服务器错误,所以您甚至没有到达端点。试着看看你的日志。使用
$this->withoutExceptionHandling()
进行完整的堆栈跟踪。不幸的是,我无法访问日志,因为在我的机器上它工作正常,只有在buddy works运行测试时它才会失败。Tests\Feature\ProductsControllerTest::test\u products\u route\u unauthenticated\u用户预期状态代码401但收到500。断言false为true失败/buddy/management-products-api-3/vendor/laravel/framework/src/illusted/Foundation/Testing/TestResponse.php:133/buddy/management-products-api-3/tests/Feature/products-controllertest.php:45失败!您是否使用Postman或其他工具来测试您的API。因为显然您的
api/订单
无法访问,因此500。你必须检查应用程序是否在服务器上运行。你的日志怎么说?一个500应该留下一个entry500意味着服务器错误,所以您甚至没有到达端点。试着看看你的日志。使用
$this->withoutExceptionHandling()
进行完整的堆栈跟踪。不幸的是,我无法访问日志,因为在我的机器上它工作正常,只有在buddy works运行测试时它才会失败。Tests\Feature\ProductsControllerTest::test\u products\u route\u unauthenticated\u用户预期状态代码401但收到500。断言false为true失败/buddy/management-products-api-3/vendor/laravel/framework/src/illusted/Foundation/Testing/TestResponse.php:133/buddy/management-products-api-3/tests/Feature/products-controllertest.php:45失败!您是否使用Postman或其他工具来测试您的API。因为显然您的
api/订单
无法访问,因此500。你必须检查应用程序是否在服务器上运行。