From 7bd199a2cac23f6b31ccc2226ee7ea5781b0c182 Mon Sep 17 00:00:00 2001 From: Pushpak Chhajed Date: Fri, 3 Oct 2025 16:23:09 +0530 Subject: [PATCH 1/2] Refactor the user factory to include withoutTwoFactor method and update tests to use it --- database/factories/UserFactory.php | 15 +++++++++++++++ tests/Feature/Auth/AuthenticationTest.php | 2 +- .../Settings/TwoFactorAuthenticationTest.php | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 584104c9..8c37266b 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, ]); } + + /** + * IIndicate 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()]) From 4cd9fb4c820dbe130c5472d7419b960c15ef0f4f Mon Sep 17 00:00:00 2001 From: Pushpak Chhajed Date: Fri, 3 Oct 2025 16:30:50 +0530 Subject: [PATCH 2/2] Fix typo in the UserFactory docblock --- database/factories/UserFactory.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 8c37266b..07af023a 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -46,7 +46,7 @@ public function unverified(): static } /** - * IIndicate that the model does not have two-factor authentication configured. + * Indicate that the model does not have two-factor authentication configured. */ public function withoutTwoFactor(): static {