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

Sajjadist's avatar

Tests Do Not Detect Routes

Hey Devs,

I created a route that functions OK, but my tests are unable to detect it. Since the test is of type feature, all Laravel features should be included.

Manipulating the closure to return a view or use a specific controller, clearing the cache, and dump autoload haven't resolved the issue.

I recently updated both my Composer and npm packages, including Laravel itself. Could this be the root cause of the problem?

Pest.php

pest()->extend(Tests\TestCase::class)
    ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
    ->in('Feature', 'Unit');

RouteTest.php

test('example', function () {
    $response = $this->get('/');

    $response->assertStatus(200);
});

web.php

Route::get('/', function () {
   dd('Welcome!');
});

Test Error:

   FAILED  Tests\Feature\routes\ProjectRouteTest > example                                                                          
  Expected response status code [200] but received 404.
Failed asserting that 404 is identical to 200.

  at tests/Feature/routes/ProjectRouteTest.php:6
      2▕ 
      3▕ test('example', function () {
      4▕     $response = $this->get('/');
      5▕ 
  ➜   6▕     $response->assertStatus(200);
      7▕ });
      8▕ 


  Tests:    1 failed (1 assertions)
  Duration: 0.25s

Thank you in advance. I've been hung up on it for a while

0 likes
8 replies
Sajjadist's avatar

This is bootstrap/app.php if it crossed your mind:

<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__.'/../routes/web.php',
        commands: __DIR__.'/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        //
    })->create();
JussiMannisto's avatar

Do you see the route when you run the command below?

php artisan route:list --env=testing
1 like
JussiMannisto's avatar

@Sajjadist Did you follow Laravel's upgrade guide when upgrading the framework version, especially with regard to any PHPUnit changes?

I'd check the configuration at phpunit.xml and .env.testing, if you have that file. You can compare your phpunit.xml to the newest shipped version to see if there are any differences.

By the way, calling dd() ends execution, and would return a 500 error in normal use. You should probably return a string instead when testing.

Sajjadist's avatar

@JussiMannisto Yes, I follow Laravel's upgrade guide and mine composer.json looks like this: No need to mention I installed them.

    "require": {
        "php": "^8.2",
        "laravel/framework": "^12.0",
        "laravel/tinker": "^2.10.1"
    },
    "require-dev": {
        "fakerphp/faker": "^1.23",
        "laravel/breeze": "^2.3",
        "laravel/pail": "^1.2.2",
        "laravel/pint": "^1.13",
        "laravel/sail": "^1.41",
        "mockery/mockery": "^1.6",
        "nunomaduro/collision": "^8.6",
        "pestphp/pest": "^3.8",
        "pestphp/pest-plugin-laravel": "^3.1"
    },

As I mentioned earlier, returning strings or using dedicated controllers didn't solve the problem.

tisuchi's avatar

@sajjadist Is that none of your routes has been detected?

Can you try also clearning by:

php artisan route:clear
php artisan config:clear
php artisan cache:clear
1 like
Sajjadist's avatar

@tisuchi I tried clearing the cache, but none of the routes are detected by the tests.

Please or to participate in this conversation.