Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Pest Plugin Route Testing Laravel Package

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().

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Non-intrusive: The package leverages Laravel’s existing testing infrastructure (Pest + Laravel TestResponse) without requiring changes to core application logic or routing definitions.
    • Complementary to existing workflows: Integrates seamlessly with Pest (a PHP testing framework) and Laravel’s built-in HTTP testing capabilities, reducing cognitive load for developers already familiar with these tools.
    • Focused scope: Targets a specific, high-value pain point (route validation) without over-engineering, aligning with the "test everything" philosophy of modern Laravel applications.
    • Extensible assertions: Supports all TestResponse assertions (e.g., assertRedirect, assertForbidden), enabling granular control over route behavior validation.
  • Cons:

    • Limited to GET routes by default: While the package skips model-binding routes by default, this may exclude critical POST/PUT/DELETE routes unless explicitly included. Requires intentional configuration to broaden coverage.
    • No dynamic payload testing: Focuses solely on HTTP status codes and basic assertions; does not validate request/response payloads (e.g., JSON schemas, form data) or middleware behavior beyond status codes.
    • Static route testing: Tests routes in isolation, which may miss integration issues (e.g., database dependencies, auth middleware interactions) that surface only in end-to-end flows.

Integration Feasibility

  • Low-risk adoption: The package is a single Composer dependency with zero configuration required for basic usage. Pest integration is minimal (one use statement and a test file).
  • Laravel version compatibility: Explicitly supports Laravel 10+ (as of 2025-08-24), with backward compatibility likely for Laravel 9. The MIT license and active maintenance reduce versioning risks.
  • Toolchain synergy: Works natively with Pest, Laravel’s 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.

Technical Risk

  • False positives/negatives:
    • Risk: Routes may pass tests even if they rely on external services (e.g., APIs, queues) or dynamic data (e.g., database records). Conversely, routes might fail tests due to missing test data (e.g., auth users, seeded data).
    • Mitigation: Pair with Laravel’s actingAs() or withoutMiddleware() for auth/testing edge cases, and use bind() for model-binding routes. Document assumptions in test files.
  • Performance overhead:
    • Risk: Testing all routes in a large application (e.g., 500+ routes) could slow down CI pipelines or local development.
    • Mitigation: Scope tests to critical paths (e.g., include('admin*')) or run in parallel using Pest’s --parallel flag.
  • Test flakiness:
    • Risk: Non-deterministic failures (e.g., rate-limited APIs, transient database locks) could destabilize tests.
    • Mitigation: Exclude flaky routes via exclude() or mock external dependencies using Laravel’s MockFacade.

Key Questions

  1. Coverage strategy:
    • Should we test all routes (*) or prioritize high-traffic/critical paths (e.g., include('checkout*'))?
    • How will we handle routes with dynamic data (e.g., user-specific routes)? Will we use bind() or mock dependencies?
  2. CI/CD integration:
    • Should route tests run in all environments (dev/staging/prod) or only in CI?
    • How will we handle test failures (e.g., block merges, notify Slack, or deprioritize non-critical routes)?
  3. Maintenance:
    • Who will own updating tests when routes change (e.g., refactoring, new features)?
    • How will we ensure tests stay in sync with route definitions (e.g., automated checks for orphaned tests)?
  4. Edge cases:
    • How will we test routes with complex middleware (e.g., rate limiting, localization) or auth requirements?
    • Should we validate non-HTTP routes (e.g., API endpoints, webhooks) or focus solely on web routes?

Integration Approach

Stack Fit

  • Primary stack compatibility:
    • Laravel 10+: Native support with zero configuration for core features.
    • Pest: First-class integration; leverages Pest’s fluent syntax and test helpers.
    • PHPUnit: Fallback option if Pest is not used (though Pest is recommended for syntax sugar).
    • Testing tools: Works with Laravel’s HttpTesting traits (e.g., withoutMiddleware, actingAs) and TestResponse assertions.
  • Secondary stack considerations:
    • API testing: Can test API routes (e.g., Route::prefix('api')) but requires explicit inclusion (e.g., include('api/*')).
    • Queue/worker routes: May need mocking for routes that trigger jobs (e.g., assertQueued()).
    • Browser automation: Not a replacement for tools like Laravel Dusk or Playwright for UI-specific tests.

Migration Path

  1. Assessment phase:
    • Audit existing routes using php artisan route:list to identify gaps in test coverage.
    • Document critical routes (e.g., payment flows, admin panels) that require priority testing.
  2. Initial integration:
    • Install the package:
      composer require --dev spatie/pest-plugin-route-testing
      
    • Add a basic test file (e.g., tests/Feature/RouteTests.php):
      use function Spatie\RouteTesting\routeTesting;
      
      it('has all GET routes returning 200', function () {
          routeTesting('all GET routes')
              ->assertSuccessful();
      });
      
    • Run tests locally and in CI to establish a baseline.
  3. Iterative refinement:
    • Phase 1: Test all GET routes with assertSuccessful().
    • Phase 2: Add granular assertions (e.g., assertRedirect() for login routes, assertForbidden() for unauthorized access).
    • Phase 3: Include non-GET routes (e.g., ->methods(['GET', 'POST'])) and exclude flaky routes.
    • Phase 4: Integrate with CI/CD to block merges on critical route failures.

Compatibility

  • Laravel features:
    • Route model binding: Skipped by default; use bind() to provide test models.
    • Middleware: Tests execute middleware in the same order as production. Use withoutMiddleware() to isolate specific routes.
    • Route caching: Works with cached routes (e.g., php artisan route:cache).
    • API resources: Validates responses but does not deep-check payload structure (pair with assertJson() for APIs).
  • Third-party packages:
    • Auth packages: Test auth routes with actingAs() or withoutMiddleware('auth').
    • Localization: Test locale-specific routes with app()->setLocale().
    • Rate limiting: Mock or exclude rate-limited routes to avoid flakiness.

Sequencing

  1. Pre-requisites:
    • Ensure Pest is installed (composer require pestphp/pest --dev --with-all-dependencies).
    • Verify Laravel’s testing environment is configured (e.g., .env.testing, database migrations).
  2. Order of operations:
    • Step 1: Integrate the package and run a broad test suite to identify missing/broken routes.
    • Step 2: Refine tests to exclude non-critical or flaky routes and add specific assertions.
    • Step 3: Automate in CI/CD with appropriate failure handling (e.g., allowlist for non-critical routes).
    • Step 4: Extend to test POST/PUT/DELETE routes as needed.
  3. Dependencies:
    • Route tests should run after database migrations/seeding in CI to avoid "missing model" errors.
    • For API-heavy apps, prioritize API route tests over web routes if resource constraints exist.

Operational Impact

Maintenance

  • Test updates:
    • Proactive: Route tests should be updated whenever routes are added, modified, or deprecated. Use Git hooks or CI checks to alert on orphaned tests.
    • Automation: Consider a script to compare route:list output with test files to detect drift.
  • False positives:
    • Maintain a list of excluded routes (e.g., exclude('webhook*')) for known flaky or non-critical routes, documented in README.md.
  • Dependency management:
    • Monitor the package for updates (e.g., Laravel 11 compatibility) and test against new versions in a staging environment.

Support

  • Developer onboarding:
    • Document the purpose of route tests (e.g., "ensures no regressions in route accessibility") and how to update them.
    • Provide templates for common test cases (e.g., auth routes, API endpoints).
  • Debugging:
    • Use Pest’s --debug flag to inspect failing routes and their responses.
    • Leverage Laravel’s dd() or dump() in test assertions for complex debugging.
  • Escalation paths:
    • Route
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport