Reputation: 7105
I use Laravel 5.8 and have test method like this this
public function test_store()
{
$attribute= ['lead_name'=>'test_name','lead_family'=>'test_family'];
$this->post('/leads', $attribute);
$this->assertDatabaseHas('leads', $attribute);
}
and controller like this:
class LeadController extends Controller
{
public function store(Request $request)
{
Lead::create($request->all());
}
}
and route :
Route::resource('/leads', 'App\Http\Controller\LeadController');
When I run phpunit show me this error:
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.
I see and read this post https://stackoverflow.com/questions/23593892/symfony-component-httpkernel-exception-notfoundhttpexception-laravel
Upvotes: 3
Views: 4425
Reputation: 7105
I solved it. I change to config\app.php
file
'url' =>'http://localhost/myscript_addres/public',
To
'url' =>'http://localhost/',
Upvotes: 2
Reputation: 38584
Set your router like this
Route::resource('leads', 'LeadController');
Make sure LeadController
placed in app/Http/Controller
Read Laravel - Route::resource vs Route::controller
Upvotes: 2