Mohammed-H's avatar

SignIn a user for Unit test on laravel 5.4

How do you signIn a user in unit test on Laravel 5.4? I tried actingAs but didn't work :(

Thanks Mohammed

0 likes
4 replies
tykus's avatar

How are you using actingAs; it takes a user instance rather than an id.

Mohammed-H's avatar

@tykus yep I use a user instance. The issue is that i have a model observer listening to the creating event and needs the authenticated user id. I am getting null

Mohammed-H's avatar

finally got it fixe, I used the auth() helper to log a user in the boot method.

Please or to participate in this conversation.