I have this code in my web.php:
Route::middleware('auth:sanctum')->group(function () {
Route::prefix('webshop')->group(function () {
Route::get('basket', [BasketController::class, 'show'])->name(RouteName::BASKET_SHOW);
});
});
In the controller:
public function show(PublicViewBasketRequest $request)
{
// ...
}
And in my test file:
/** @test */
public function shouldShowAsAuthorizedUser(): void
{
// ...
$this->get(action([$this->controller, 'show']))
->assertOk();
// ...
}
When I run php artisan route:list | grep basket command I see this line in the result:
GET|HEAD webshop/basket basket.show › Domain\Webshop\Http\Controller…
PUT webshop/basket basket.update › Domain\Webshop\Http\Controll…
And when I run the test I get this result:
1) Domain\Webshop\Tests\Basket\BasketControllerRegisteredMemberTest::shouldShowAsAuthorizedUser
Expected response status code [200] but received 404.
Failed asserting that 200 is identical to 404.
So the route actually exists, but the test call don't see it.
I found out if I use the route like this:
Route::get('my/basket', [BasketController::class, 'show'])->name(RouteName::BASKET_SHOW);
...then the test is pass. (The modification is the my/ part of the route. The my word is can be any word. The slash is the point with two words/strings.)
So the question is why don't working the route without my/ part? What is the hidden Laravel magic behind this issue?