laravel route parameters return null on unittest

664 Views Asked by At

I got a problem on phpunit I'm design route as

/v1/outlet/{outlet_id}/test


Route::get('outlets/{outlet_id}/test', ['as' => 'test'], function(){
    return app('request')->route('outlet_id');
});

It's working when i call it in postman or brower but in phpunit show out as error

Call to a member function parameter() on array

test code

$req = $this->call('GET', '/v1/outlets/1/test');
$this->assertResponseStatus(200);
2

There are 2 best solutions below

2
On

You have outlets plural in your test but outlet singular in your route definition.

0
On

Please remove the code use WithoutMiddleware from your testing class if it is there and try.