我使用的是 Laravel 5.8 并且有这样的测试方法
public function test_store()
{
$attribute= ['lead_name'=>'test_name','lead_family'=>'test_family'];
$this->post('/leads', $attribute);
$this->assertDatabaseHas('leads', $attribute);
}
和这样的 Controller :
class LeadController extends Controller
{
public function store(Request $request)
{
Lead::create($request->all());
}
}
和路线:
Route::resource('/leads', 'App\Http\Controller\LeadController');
当我运行 phpunit 时显示这个错误:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException: POST http://localhost/myproject/public/leads
C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling.php:118 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:326 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php:120 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests.php:375 C:\wamp64\www\myproject\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\MakesHttpRequests.php:197 C:\wamp64\www\myproject\tests\Feature\Customer\LeadTest.php:38 I test
leads
URL with Postman and it work correctly.
最佳答案
这样设置你的路由器
Route::resource('leads', 'LeadController');
确保 LeadController
放在 app/Http/Controller
关于php - Laravel 5 交响乐\组件\HttpKernel\异常\NotFoundHttpException : POST http://localhost/myproject/public/leads,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59007864/