spatie/pest-plugin-route-testing
Pest plugin for Laravel that automatically tests all your app’s GET routes. Run a single test to assert responses are successful, redirects, forbidden, not found, etc. Filter routes by pattern and provide models for route model bindings via bind().
Pros:
TestResponse assertions (e.g., assertRedirect, assertForbidden), enabling granular control over route behavior validation.Cons:
use statement and a test file).Testing facade, and CI/CD pipelines (e.g., GitHub Actions) that already run PHPUnit/Pest tests. No additional infrastructure (e.g., browser automation) is required.actingAs() or withoutMiddleware() for auth/testing edge cases, and use bind() for model-binding routes. Document assumptions in test files.include('admin*')) or run in parallel using Pest’s --parallel flag.exclude() or mock external dependencies using Laravel’s MockFacade.*) or prioritize high-traffic/critical paths (e.g., include('checkout*'))?bind() or mock dependencies?HttpTesting traits (e.g., withoutMiddleware, actingAs) and TestResponse assertions.Route::prefix('api')) but requires explicit inclusion (e.g., include('api/*')).assertQueued()).php artisan route:list to identify gaps in test coverage.composer require --dev spatie/pest-plugin-route-testing
tests/Feature/RouteTests.php):
use function Spatie\RouteTesting\routeTesting;
it('has all GET routes returning 200', function () {
routeTesting('all GET routes')
->assertSuccessful();
});
assertSuccessful().assertRedirect() for login routes, assertForbidden() for unauthorized access).->methods(['GET', 'POST'])) and exclude flaky routes.bind() to provide test models.withoutMiddleware() to isolate specific routes.php artisan route:cache).assertJson() for APIs).actingAs() or withoutMiddleware('auth').app()->setLocale().composer require pestphp/pest --dev --with-all-dependencies)..env.testing, database migrations).route:list output with test files to detect drift.exclude('webhook*')) for known flaky or non-critical routes, documented in README.md.--debug flag to inspect failing routes and their responses.dd() or dump() in test assertions for complex debugging.How can I help you explore Laravel packages today?