@krisi_gjika I’m trying to write tests for each user status (active, pending_verification, disabled) to make sure they can only access the routes they’re allowed to. For example, a pending user should be able to access /verify or /resend, but should be blocked from all other routes.
My issue is: I’m not sure how to write a test that automatically checks all the other routes the user is not allowed to access, without having to manually list them all. Any suggestions on how to structure this kind of test?
@a.verrecchia I think rather than trying to check every route in one test, you should test the rest as normal. Example when testing if user can make posts, also test that pending users can't make posts
I'd just manually list all testable routes and the exception cases. You could get all routes using Route::getRoutes() and manually list only the exceptions, but that has some drawbacks.
Firstly, you have to consider routes registered by the framework or packages, like the health check route and routes from Telescope, Debugbar, Pulse, etc.
Secondly, if your app ever gets any routes with parameters or model bindings, this automation will fail. Whoever is adding the route has to stop what they're doing and rewrite this test.
I think it's better to be explicit with the test cases.