mardi 24 juillet 2018

How can I autheticate user for Laravel feature testing?

I am trying to test if authenticated manager will redirect to dashboard. (When the manager is already authenticated and goes to login page, he is redirected to dashboard)

public function testIfBackendIsLoggingAuthenticatedUser()
{
    $manager = \App\Manager::where('email', 'test@email.com')->first();
    Auth::attempt(['email' => $manager->email, 'password' => $manager->password]);

    $response = $this->actingAs($manager)
        ->get(route('backend.login.show'))
        ->assertRedirect(route('backend.dashboard.index'));
}

But I get the result

Response status code [200] is not a redirect status code.
Failed asserting that false is true.

How can I make authentication test?

Aucun commentaire:

Enregistrer un commentaire