Skip to content

Commit 0b14688

Browse files
committed
Refactor the user factory to include withoutTwoFactor method and update tests to use it
1 parent 1936a8d commit 0b14688

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

database/factories/UserFactory.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public function definition(): array
2929
'email_verified_at' => now(),
3030
'password' => static::$password ??= Hash::make('password'),
3131
'remember_token' => Str::random(10),
32+
'two_factor_secret' => Str::random(10),
33+
'two_factor_recovery_codes' => Str::random(10),
34+
'two_factor_confirmed_at' => now(),
3235
];
3336
}
3437

@@ -41,4 +44,16 @@ public function unverified(): static
4144
'email_verified_at' => null,
4245
]);
4346
}
47+
48+
/**
49+
* Indicate that the model does not have two-factor authentication configured.
50+
*/
51+
public function withoutTwoFactor(): static
52+
{
53+
return $this->state(fn (array $attributes) => [
54+
'two_factor_secret' => null,
55+
'two_factor_recovery_codes' => null,
56+
'two_factor_confirmed_at' => null,
57+
]);
58+
}
4459
}

tests/Feature/Auth/AuthenticationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function test_login_screen_can_be_rendered()
2121

2222
public function test_users_can_authenticate_using_the_login_screen()
2323
{
24-
$user = User::factory()->create();
24+
$user = User::factory()->withoutTwoFactor()->create();
2525

2626
$response = $this->post(route('login.store'), [
2727
'email' => $user->email,

tests/Feature/Settings/TwoFactorAuthenticationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function test_two_factor_settings_page_can_be_rendered()
2323
'confirmPassword' => true,
2424
]);
2525

26-
$user = User::factory()->create();
26+
$user = User::factory()->withoutTwoFactor()->create();
2727

2828
$this->actingAs($user)
2929
->withSession(['auth.password_confirmed_at' => time()])

0 commit comments

Comments
 (0)