BrownieCoffee
2 months ago
20
13
Testing

The current user is not authenticated PHPUnit

Posted 2 months ago by BrownieCoffee

Hello guys, are are you?

Can you help me to fix this error please?

I try since 1 week to fix that but nothing yet.

I did test to know if a user can login

    public function user_can_login_with_valid_fields(){


        $user = factory(User::class, 1)->create([
            'password' => bcrypt('i-love-laravel'),
        ]);
    
       $response = $this->post(route('connexion'), [
            'email' => $user->email,
            'password' => 'i-love-laravel',
        ]);


        $response->assertRedirect(route('home'));

        $this->assertAuthenticatedAs($user);
     }


...but I have this error:

Time: 5.51 seconds, Memory: 24.00 MB

There was 1 failure:

1) Tests\Feature\LoginTest::user_can_login_with_valid_fields
The current user is not authenticated.
Failed asserting that null is not null.

/var/www/html/goshr/vendor/laravel/framework/src/Illuminate/Foundation/Testing/Concerns/InteractsWithAuthentication.php:89
/var/www/html/goshr/tests/Feature/LoginTest.php:53
/home/audrey/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:201
/home/audrey/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:160

I searched on the internet without find a solution. I hope you help me for that !

Thank you by advance and see you soon.

ps: sorry for my english.

Please sign in or create an account to participate in this conversation.