the test environment doesn't consider my class LoginResponse.php to redirect the user depending on its role
How are you actually testing this?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi! I have an application with many user roles, so I've implemented this solution: https://laracasts.com/discuss/channels/laravel/version-8-redirects?page=1&replyId=639873
Everything work perfectly. However, I'm creating some features tests, and I want to test the login system. My problem resides that the test environment doesn't consider my class LoginResponse.php to redirect the user depending on its role, and it uses the HOME variable defined in RouteServiceProvider.
Does someone have the same problem as me?
Thanks!
@savins this doesn't make sense:
$response = $this->actingAs($user)->post("/login");
You are acting as the User (i.e. authenticated already); and, you are attempting to sign in without credentials!
public function test_user_admin(){
$user = User::factory()->create(['active'=>true]);
$role_admin = Role::factory()->create(["name"=>"admin"]);
$user->getRoles()->attach($role_admin);
$response = $this->post("/login", [
'email' => $user->email,
'password' => 'secret', // this is the default Factory password!
]);
$this->assertAuthenticated();
$response->assertRedirect("dashboard");
}
Please or to participate in this conversation.