Expected status code 200 but received 302.
Failed asserting that 200 is identical to 302.
and PHPStorm say, when i hover above actingAs($user):
Expected parameter of type '\Illuminate\Contracts\Auth\Authenticatable', '\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model' provided
Your user model should implement \Illuminate\Contracts\Auth\Authenticatable interface.
you can do this and all laravel default user authentication stuff to your user model by extending
Illuminate\Foundation\Auth\User class in your user model.
Now I didn't quite understand that. Authenticatable is already in the user model. And my other models should now no longer inherit from "Model", but from Illuminate\Foundation\Auth\User?
302 means redirected. I take it you are using breeeze, jetstream or laravel ui? If so a logged in user should be redirected when hitting the register route.
@tray2 i don't think so.
i think he is being redirected to login page because the user he is giving to actingAs method is not implementing Authenticable contract as i said above.
Not the case I expect. More likely an authenticated user should not be able to see the Register page, and is automatically redirected. So the test expectation actually is incorrect.
I agree with this. I just tried it on my fresh laravel installation. I got the test running correctly but my IDE phpstorm is complaining. do we have a fix to this?
The idea in the test is to call the user factory and create a user, take it and then get to the protected page. So it would be e.g. ->get('clients') or something like that.
Register I tried because I wanted to see if a new user could look at pages that are public.
The idea in the test is to call the user factory and create a user, take it and then get to the protected page.
Yes. Authenticated (and authorized if relevant) should get a 200 response; while unauthenticated (and unauthorized) would be 401 and 403 respectively. If you have exception handling enabled, then the framework will handle those exceptions, and redirect (302) the request appropriately.
if a new user could look at pages that are public
Typically, endpoints such as register are protected with the guest middleware, so an authenticated user cannot visit them.
I could be unrelated but... why an already authenticated user would like to register ? this is an action for unauthenticated user only ?
Maybe check the destination route is correct
Also where are you redirected to ? what is the 'location' header in the response ?
If you have xdebug with step debugging, maybe check if Exceptions are thrown during the request. it would help to understand if it's an authentication problem or not.