Hi everyone,
I have a code like below
$user = \App\User::where('email', trim($this->email))->firstOrFail();
//compare password
if (! Hash::check(trim($this->password), $user->password) ) {
throw new \Illuminate\Database\Eloquent\ModelNotFoundException;
}
$user->update([
'auth_token' => custom_unique('AUTH_TOKEN'),
]);
Auth::login($user, true);
return $user;
which throws an exception when the password is not valid and I try to test for this scenario with below code but tests fail:
public function testWrongCredentialThrowsException()
{
$this->withoutExceptionHandling();
$attributes = [
'email' => ' [email protected] ',
'password' => 'abc',
];
$user = factory(\App\User::class)->create($attributes);
$this->post('/api/auth/store', $attributes)->assertSuccessful();
$user = \App\User::where('email', '=', trim($attributes['email']))->first();
if (!Hash::check('abcd', $user->password)) {
$this->expectException(ModelNotFoundException::class);
}
}
Please can you help me check what I am doing wrong