gpt4 book ai didi

php - Laravel PHPUnit 返回 404

转载 作者:行者123 更新时间:2023-12-03 16:59:08 25 4
gpt4 key购买 nike

对于laravel API,我已经编写了测试用例。但是每当我运行测试用例时,它总是因以下错误而失败,

1) Tests\Feature\CompanyTest::orgTest
Expected status code 200 but received 404.
Failed asserting that 200 is identical to 404.
添加后 $this->withoutExceptionHandling();测试用例代码它返回以下错误,
1) Tests\Feature\CompanyTest::orgTest
Symfony\Component\HttpKernel\Exception\NotFoundHttpException: POST domainname/index.php/api/company

/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithExceptionHandling.php:126
/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:415
/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:113
/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:507
/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:473
/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/MakesHttpRequests.php:332
/tests/Feature/CompanyTest.php:21

My Code in Test File is,

public function orgTest()
{
$requestData = ["organizationId" => 10,"offset"=>1,"limit"=>10,"notificationId"=>""];
$response = $this->withoutExceptionHandling();
$response->postJson('/index.php/api/company',$requestData);
$response->assertStatus(200);
}
我用谷歌搜索了错误并尝试了许多解决方案但无法成功。任何人请让我知道是什么问题。

最佳答案

这是一个 404 错误,因此找不到您的网页:

Symfony\Component\HttpKernel\Exception\NotFoundHttpException: POST domainname/index.php/api/company
不好走,发帖到 /api/company或与 /index.php/api/company但不是“域名”!
如果它不起作用,请检查该 API 路由的路由配置。你的 Controller 和 Action 声明得好吗?

关于php - Laravel PHPUnit 返回 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63340871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com