danpinzaru93's avatar

Test Authentification using Cookies

Laravel Version: 5.1

Hi guys! I would like to be able to write a test where a login request is issued and the cookie that I have set for the user is being used to authenticate the user.

My current attempt is to perform the login using the Auth::attempt() function with the 'remember' option set to true, I check that the cookie is being set and indeed it is, so now what I want to do is to issue another login request to check that the cookie is actually being used,

The reason I'm struggling right now is that the $user object is already available in the Illuminate\Auth.php class after I issue the first login attempt, so it basically does not need to check the cookie. Is there any way I can force the authentication to use the cookie?

I would imagine I would have to create a new $app instance in the test so that the AuthServiceProvider registers the AuthManager again.

I'm writing the test in PHPUnit.

Thank you in advance!

0 likes
0 replies

Please or to participate in this conversation.