【发布时间】:2020-03-19 07:55:14
【问题描述】:
我使用 Laravel 5.8 并且有这样的测试方法
public function test_store()
{
$attribute= ['lead_name'=>'test_name','lead_family'=>'test_family'];
$this->post('/leads', $attribute);
$this->assertDatabaseHas('leads', $attribute);
}
和这样的控制器:
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 我用 Postman 测试了
leadsURL,它工作正常。
【问题讨论】:
-
你可以运行
php artisan route:list看看你有没有预定的路线 -
是的,它存在。我用邮递员测试了它,它工作正常。
-
在这种情况下,我建议尝试清除缓存并执行 composer dump autoload。看看有没有帮助
-
我做了但没用
标签: php laravel symfony laravel-5 phpunit