Summer Sale! All accounts are 50% off this week.

uniquelypi's avatar

Weird Laravel Testing probem.

Hi everyone,

I've searched and searched and couldn't find the issue.

I have a laravel 7 repo. I've a suite of tests that , In the local environment, everything works.

However, once it's in a development server, it won't authenticate.

I get:

Expected status code 200 but received 302. Failed asserting that 200 is identical to 302.

I'm using actingAs(User::find(43)) and I've doubled checked the that user is correct by doing:

$user = User::find(43);

and actingAs($user)

Again, the same code works in the local environment but not on a development server.

What could be the reason?

0 likes
3 replies
Tray2's avatar

You receive a 302 and that is a redirect, so I am guessing that you are redirected back to the login page.

I would probably check the location rather than the status.

Without any code it's hard to help.

uniquelypi's avatar

HI thanks for the reply.

I've solved this issue but I am still really baffled as to why. Here's the solution.

The solution was to rename the user's name in the database. Nothing else changed.

The name of the user went from "TestUser" to "PHP Testing".

Bear in mind, the same DB / App is testing fine in local.

Anyway, Thanks!

MohamedTammam's avatar

Don't use fixed IDs in your tests, use model factory to generate a model for you tests instead. Every environment will have different users data for each ID.

Please or to participate in this conversation.