Summer Sale! All accounts are 50% off this week.

alberto98's avatar

Testing password reset

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?

0 likes
3 replies
alberto98's avatar

@Nakov Thanks, this will help me but I think I need to understand first what they're doing there.

alberto98's avatar
alberto98
OP
Best Answer
Level 1

For everyone reading here, I've found a better way:

        $token = Password::broker()->createToken($user);

Please or to participate in this conversation.