1
votes

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://stackguides.com/questions/23593892/symfony-component-httpkernel-exception-notfoundhttpexception-laravel

2
can you run php artisan route:list and see you have got the intended routealithedeveloper
Yes it's exists. I tested it with postman and it worked correctly.paranoid
In that case i would suggest try clearing your cache and do composer dump autoload. see if that helpsalithedeveloper
I do it but not workparanoid

2 Answers

1
votes

Set your router like this

Route::resource('leads', 'LeadController');

Make sure LeadController placed in app/Http/Controller

Read Laravel - Route::resource vs Route::controller

0
votes

I solved it. I change to config\app.php file

'url' =>'http://localhost/myscript_addres/public',

To

'url' =>'http://localhost/',