PHPackages                             spatie/pest-plugin-route-testing - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. spatie/pest-plugin-route-testing

ActiveLibrary[Framework](/categories/framework)

spatie/pest-plugin-route-testing
================================

Make sure all routes in your Laravel app are ok

1.1.4(10mo ago)13872.4k—4.6%6MITPHPPHP ^8.1CI passing

Since May 31Pushed 9mo ago3 watchersCompare

[ Source](https://github.com/spatie/pest-plugin-route-testing)[ Packagist](https://packagist.org/packages/spatie/pest-plugin-route-testing)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-pest-plugin-route-testing/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (7)Versions (13)Used By (0)

Make sure all routes in your Laravel app are ok
===============================================

[](#make-sure-all-routes-in-your-laravel-app-are-ok)

In a typical Laravel application there are many pages that can be accessed by users. It's easy to forget to test all of them. This package makes it easy to test all GET routes in your application.

Here's a quick example:

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all GET routes')
   ->assertSuccessful();
```

This will test all GET routes in your application and ensure they return a 200 HTTP status code. Here's what the output looks like when you run this test in a small app.

[![screenshot](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/all.png)](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/all.png)

Instead of `assertSuccessful()` you can use any assertion that is available in Laravel's `TestResponse` class, such as `assertRedirect()`, `assertNotFound()`, `assertForbidden()`, etc.

You can also test specific routes:

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all blog routes')
    ->include('blog*')
    ->assertSuccessful();
```

If you there are routes that have route model bindings, the package will skip the test for those routes. Let's assume you have a route defined as `user/{user}`. Here's what the output looks like when you run the test.

[![screenshot](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-missing.png)](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-missing.png)

If you want to test a route with a route model binding, you can provide the model using the `bind` method.

```
use function Spatie\RouteTesting\routeTesting;
use App\Models\User;

routeTesting('all blog routes')
    ->bind('user', User::factory()->create())
    ->assertSuccessful();
```

When you run the test now, the package will use the provided model to test the route.

[![screenshot](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-ok.png)](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-ok.png)

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/9b85c24f6587b06e227bbdb00eb7dca971669a1311d2a94c2ea966d25c03cf09/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d7064662e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-pdf)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/pest-plugin-route-testing --dev
```

Usage
-----

[](#usage)

You can use the `routeTesting` function to test all routes in your application.

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all routes')
    ->assertSuccessful();
```

This will test all GET routes in your application and ensure they return a 200 HTTP status code. Here's what the output looks like when you run this test in a small app.

[![screenshot](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/all.png)](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/all.png)

Instead of `assertSuccessful()` you can use any assertion that is available in Laravel's `TestResponse` class, such as `assertRedirect()`, `assertNotFound()`, `assertForbidden()`, etc.

Here's an example where we test if a redirect is working.

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('redirect')
    ->include('old-section/*')
    ->assertRedirect('new-section/*');
```

### Testing specific routes

[](#testing-specific-routes)

You can test specific routes by using the `include` method. There is support for wildcards. Here's an example that tests all routes that start with `blog`.

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all blog routes')
    ->include('blog*')
    ->assertSuccessful();
```

You can also pass as many arguments as you want to the `include` method.

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all blog routes')
    ->include('blog*', 'post*')
    ->assertSuccessful();
```

### Excluding routes

[](#excluding-routes)

If you want to exclude routes from the test, you can use the `exclude` method. Here's an example that tests all routes except the ones that start with `admin`.

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all blog routes')
    ->exclude('admin*')
    ->assertSuccessful();
```

### Binding route model bindings

[](#binding-route-model-bindings)

If you there are routes that have route model bindings, the package will skip the test for those routes. Let's assume you have a route defined as `user/{user}`. Here's what the output looks like when you run the test.

[![screenshot](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-missing.png)](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-missing.png)

If you want to test a route with a route model binding, you can provide the model using the `bind` method.

```
use function Spatie\RouteTesting\routeTesting;
use App\Models\User;

routeTesting('all blog routes')
    ->bind('user', User::factory()->create())
    ->assertSuccessful();
```

When you run the test now, the package will use the provided model to test the route.

[![screenshot](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-ok.png)](https://raw.githubusercontent.com/spatie/pest-plugin-route-testing/main/docs/images/user-ok.png)

If you don't want to display tests that are skipped because of a missing model binding, you can call `ignoreRoutesWithMissingBindings()`.

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all blog routes')
    ->ignoreRoutesWithMissingBindings()
    ->assertSuccessful();
```

### Executing custom code before the test

[](#executing-custom-code-before-the-test)

You can use the `setUp` method to execute code before the route test is run. Here's an example where we log in a user before running the test.

```
use function Spatie\RouteTesting\routeTesting;

routeTesting('all admin routes')
    ->setUp(function ()
    {
        $user = User::factory()->create();

        $this->actingAs($user);

        // optionally, you could also bind the model
        $this->bind('user', $user);
    })
    ->include('admin*')
    ->assertSuccessful();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Niels Vanpachtenbeke](https://github.com/nielsvanpach)
- [Alex Vanderbist](https://github.com/AlexVanderbist)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance55

Moderate activity, may be stable

Popularity47

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~41 days

Recently: every ~84 days

Total

12

Last Release

313d ago

Major Versions

0.0.5 → 1.0.02024-07-18

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (51 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (49 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (11 commits)")[![mozex](https://avatars.githubusercontent.com/u/18025667?v=4)](https://github.com/mozex "mozex (3 commits)")[![ngmy](https://avatars.githubusercontent.com/u/864041?v=4)](https://github.com/ngmy "ngmy (2 commits)")[![benjaminhaeberli](https://avatars.githubusercontent.com/u/33510361?v=4)](https://github.com/benjaminhaeberli "benjaminhaeberli (2 commits)")[![GigaGiorgadze](https://avatars.githubusercontent.com/u/75663118?v=4)](https://github.com/GigaGiorgadze "GigaGiorgadze (1 commits)")[![pb30](https://avatars.githubusercontent.com/u/259602?v=4)](https://github.com/pb30 "pb30 (1 commits)")[![Sairahcaz](https://avatars.githubusercontent.com/u/7384870?v=4)](https://github.com/Sairahcaz "Sairahcaz (1 commits)")

---

Tags

laravelpestphproutestestingphppluginspatietestingunitframeworktestpestdev

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/spatie-pest-plugin-route-testing/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-pest-plugin-route-testing/health.svg)](https://phpackages.com/packages/spatie-pest-plugin-route-testing)
```

###  Alternatives

[pestphp/pest

The elegant PHP Testing Framework.

11.6k72.2M20.5k](/packages/pestphp-pest)[defstudio/pest-plugin-laravel-expectations

A plugin to add laravel tailored expectations to Pest

99600.5k8](/packages/defstudio-pest-plugin-laravel-expectations)[jonpurvis/lawman

A PestPHP Plugin to help with architecture testing SaloonPHP integrations

4138.2k10](/packages/jonpurvis-lawman)[pestphp/pest-plugin-arch

The Arch plugin for Pest PHP.

4358.2M5.5k](/packages/pestphp-pest-plugin-arch)[pestphp/pest-plugin-browser

Pest plugin to test browser interactions

1343.7M184](/packages/pestphp-pest-plugin-browser)[pestphp/pest-plugin-type-coverage

The Type Coverage plugin for Pest PHP.

354.3M1.1k](/packages/pestphp-pest-plugin-type-coverage)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
