Source: paulund.co.uk

Laravel Smoke Test Guest URLs
In this tutorial we're going to build a test class that will run through all guest URLs defined in our web.php routes and check that they all return a HTTP status of 200. Using the guest middleware will make sure that anybody can access these URLs without having to be logged in. When the URLs are wrapped in the guest middleware we can make sure we only check these URLs.

Get all guest routes Loop through each route and check if the URL is dynamic If the URL is dynamic then create a test URL Make a HTTP request to this URL Check if URL returns 200 HTTP status https://paulund.co.uk/laravel-smoke-test-guest-urls#get-all-guest-routesTo get all routes that are defined in Laravel you can use Illuminate\Routing\Router with the method getRoutes method.

https://paulund.co.uk/laravel-smoke-test-guest-urls#convert-dynamic-routesAfter we have all the routes we need to then loop through the routes, check if they're dynamic and check a test model to match the dynamic route.

The return of dynamic URL mapping function can be used to make a HTTP request then we can check to see if the HTTP status is a 200.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners