Level 73
Take a look on how Laravel tests the reset logic in laravel fortify
https://github.com/laravel/fortify/blob/1.x/tests/NewPasswordControllerTest.php
1 like
Summer Sale! All accounts are 50% off this week.
Hi all,
I'm developing an API and I'm trying to test my password reset.
This is what my method looks like (it's the same that you can find here: Laravel Docs)
$request->validate([
'token' => 'required',
'email' => 'required|email',
'password' => 'required|min:8|confirmed',
]);
$status = Password::reset(
$request->only('email', 'password', 'password_confirmation', 'token'),
function ($user, $password) {
$user->forceFill([
'password' => Hash::make($password)
])->setRememberToken(Str::random(60));
$user->save();
event(new PasswordReset($user));
}
);
return $status === Password::PASSWORD_RESET;
}
How can I test it in my UserTest if I can't recover the token sent in the previous test and I have no factory for the password_reset table?
For everyone reading here, I've found a better way:
$token = Password::broker()->createToken($user);
Please or to participate in this conversation.