It doesn't work because the session has errors. Can you show the code of your user factory? This might be related to password hash.
Jan 24, 2024
23
Level 1
assertSessionDoesntHaveErrors() is not working
I have that following test:
/** @test */
public function user_can_login_with_valid_credentials()
{
User::factory()->create([
'email' => '[email protected]',
'password' => 'password',
]);
$this->post('/login', [
'email' => '[email protected]',
'password' => 'password',
])
->assertStatus(302)
->assertSessionDoesntHaveErrors();
}
But its throwing:
1) Tests\Feature\Auth\LoginTest::user_can_login_with_valid_credentials
Session has unexpected errors:
{
"default": [
"The provided credentials do not match our records."
]
}
Failed asserting that true is false.
while the credential was right but why assertSessionDoesntHaveErrors() is not working as expected?
Level 29
@kmnurunnabi Ok I see what you're trying to do now
You also have to return true in authenticate() when the Auth::attempt is successfull
public function authenticate()
{
$this->ensureIsNotRateLimited();
if (!Auth::attempt($this->validated(), $this->boolean('remember'))) {
RateLimiter::hit($this->throttleKey());
return false;
}
RateLimiter::clear($this->throttleKey());
return true;
}
May I ask for what reason you are changing these default methods?
Please or to participate in this conversation.