Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Pixelairport's avatar

Get route in feature test

I started with testing and found a lot of examples with:

$response = $this->get('/');

But is it also possible to do something like this:

$response = $this->route('page.en.cart');

or

$response = $this->get(route('page.en.cart'));

Because nothing works... Maybe it is a bad idea, but I'm a testing beginner, and this would sound better than use path/url for me. Am I wrong?

0 likes
3 replies
oranges13's avatar

Yes, this is absolutely possible, and probably better than hard-coding URLs into your tests manually.

$response = $this->get(route('route.name.here'));

Should work fine, but make sure you're also sending in any necessary parameters. It may help us debug a specific issue if you elaborate on what exactly your route needs to function properly and what error you are seeing.

Pixelairport's avatar

Ok. I'm on the right way. I thought it should work, but it did not. I got:

  at vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:420
    416|         if (! is_null($route = $this->routes->getByName($name))) {
    417|             return $this->toRoute($route, $parameters, $absolute);
    418|         }
    419| 
  > 420|         throw new RouteNotFoundException("Route [{$name}] not defined.");
    421|     }
    422| 
    423|     /**
    424|      * Get the URL for a given route instance.

      +1 vendor frames 
  2   tests/Feature/CheckPagesTest.php:17

I created a really simple route now (the route name exist), without any special chars or grouping it. Really simple... and there is still the same problem. I can use $this->get('en/imprint'); but cant use $this->get(route('en.page.imprint'));

Pixelairport's avatar
Pixelairport
OP
Best Answer
Level 12

Ok. It works now... there was a bug in an extension i use, which scaffold extensions... it was fixed... Now everything works like expected.

Please or to participate in this conversation.