Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ckalita's avatar

Testing role access

What is your favorite way of structuring http / browser tests around user roles and permissions?

  • Do you prefer placing each under Browser\ActingAs\{Role}...Test.php?
  • Focus on routes instead and test each case within Browser{RouteName}Test.php
  • Make it all controller-name based?

I guess my question in, if i would want to have a sort of end-to-end test suite for a specific role (as their permissions, views and general functionality wildly differ), what would be the best approach?

0 likes
1 reply
mohamedallamthe1's avatar

I think it depends on the scale of your opplication, and its architecture.

  • if you are using Laravel structure, controller with controllers, model with models..ect its better to test accordingly and test controller methods, tests/Feature/Http/Controllers/OrderControllerTest ..ect like Jason McCreary suggests Confident-Laravel course.

  • If instead there more logic outside the controllers, which is really recommended you would for example test middlewares in a unit tests, and try to make a feature test. like Adam Wathan TDD course says.

  • if its a DDD project, actions are very easily unit tested, and overall you will deal with a fairly smaller classes and tests. like Spatie team would for a big project.

you can find all this courses source code open source on github.

Please or to participate in this conversation.