How to test an authorization redirect with Laravel? How to test an authorization redirect with Laravel? laravel laravel

How to test an authorization redirect with Laravel?


You have two options:

  • better create tests for user factory, like it can make user types you want
  • break with a debugger after user generation to inspect it manually

I recommend you to create tests, beacuse you have doubt now, and in future there is a chance of accidently breaking the factory code, since it's not so obvious.


As an aside: unit tests are not meant to be user experience tests. For that is would be acceptance or functional testing. One of the more popular tools for that is codeception. It combined with phantomjs or selenium can emulate a browser session and get full user experience rendering.

Per docs available at http://codeception.com/docs/01-Introduction docs:

Acceptance Tests : 'Acceptance tests can cover standard but complex scenarios from a user’s perspective. With acceptance tests you can be confident that users, following all defined scenarios, won’t get errors.'

Functional Tests : 'functional tests you emulate a web request ($_GET and $_POST variables) and send it into your application which returns HTML response. '

Unit Tests : 'Testing pieces of code before coupling them together is highly important as well. This way you can be sure that some deeply hidden feature still works, even if it was not covered by functional or acceptance tests. This also proves that you produced stable and testable code.'


I would suggest using Authenticate a User Instance Auth::login($user); for more details read here.

This method is valid for Laravel 5.x and up