diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 584104c9..07af023a 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -29,6 +29,9 @@ public function definition(): array 'email_verified_at' => now(), 'password' => static::$password ??= Hash::make('password'), 'remember_token' => Str::random(10), + 'two_factor_secret' => Str::random(10), + 'two_factor_recovery_codes' => Str::random(10), + 'two_factor_confirmed_at' => now(), ]; } @@ -41,4 +44,16 @@ public function unverified(): static 'email_verified_at' => null, ]); } + + /** + * Indicate that the model does not have two-factor authentication configured. + */ + public function withoutTwoFactor(): static + { + return $this->state(fn (array $attributes) => [ + 'two_factor_secret' => null, + 'two_factor_recovery_codes' => null, + 'two_factor_confirmed_at' => null, + ]); + } } diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index 7c2a1236..54b3ce13 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -21,7 +21,7 @@ public function test_login_screen_can_be_rendered() public function test_users_can_authenticate_using_the_login_screen() { - $user = User::factory()->create(); + $user = User::factory()->withoutTwoFactor()->create(); $response = $this->post(route('login.store'), [ 'email' => $user->email, diff --git a/tests/Feature/Settings/TwoFactorAuthenticationTest.php b/tests/Feature/Settings/TwoFactorAuthenticationTest.php index 7a5a6520..7572dfcd 100644 --- a/tests/Feature/Settings/TwoFactorAuthenticationTest.php +++ b/tests/Feature/Settings/TwoFactorAuthenticationTest.php @@ -23,7 +23,7 @@ public function test_two_factor_settings_page_can_be_rendered() 'confirmPassword' => true, ]); - $user = User::factory()->create(); + $user = User::factory()->withoutTwoFactor()->create(); $this->actingAs($user) ->withSession(['auth.password_confirmed_at' => time()])