create(); $this->postJson('/api/passwords/reset', [ 'email' => $user->email, ])->assertCreated(); Notification::assertSentTo($user, ResetPassword::class); Event::assertDispatched(ForgotPasswordRequested::class, function ($event) use ($user) { return $event->email === $user->email; }); } public function test_it_validates_input() { Notification::fake(); Event::fake([ForgotPasswordRequested::class]); $this->postJson('/api/passwords/reset', [])->assertStatus(422); Notification::assertNothingSent(); Event::assertNotDispatched(ForgotPasswordRequested::class); } public function test_it_recovers_password_with_token() { Event::fake([PasswordRecovered::class]); $user = User::factory()->create(); $broker = Password::broker(); $token = $broker->createToken($user); DB::table('password_resets')->insert([ 'email' => $user->email, 'token' => $token, 'created_at' => now(), ]); $this->putJson('/api/passwords/reset', [ 'token' => $token, 'email' => $user->email, 'password' => 'Abc123**', ])->assertOk(); Event::assertDispatched(PasswordRecovered::class, function ($event) use ($user) { return $event->user->id === $user->id; }); } public function test_it_validates_token_in_password_reset() { Event::fake([PasswordRecovered::class]); $user = User::factory()->create(); $this->putJson('/api/passwords/reset', [ 'token' => 'some-token', 'email' => $user->email, 'password' => 'Abc123**', ])->assertStatus(422); Event::assertNotDispatched(PasswordRecovered::class); } }