I have this testing method:
public function testCanResetPassword()
{
$this->call('POST', '/password/reset', [
'email' => 'test@case.com',
'_token' => csrf_token(),
])->assertStatus(200);
$token = DB::table('password_resets')->where('email', 'test@case.com')->first()->token;
$response = $this->call('POST', '/password/generate', [
'token' => $token,
'_token' => csrf_token(),
])->assertStatus(200);
$password = $response->content();
$this->assertTrue(Auth::check());
$this->assertTrue(Hash::check($password, User::where('email', 'test@case.com')->first()->password));
}
Which fails at the last 2 lines, because the reset password isn't stored in my generate method:
public function generatePassword(Request $request)
{
try {
$user = $this->getUserFromToken($request->input('token'));
}
catch (\Exception $e) {
return response('Token not found', 400);
}
$password = str_random(8);
$user->password = Hash::make($password);
$user->save();
$this->authenticate($user->email, $password);
return $password;
}
Everything seem to work when it's in non-testing environment. $this->authenticate doesn't authenticate either as $password is not really stored.
I must be missing some details here? As far as I know the password should be saved until the end of the testing method?
No responses yet.