diff --git a/tests/Feature/Auth/AuthenticationTest.php b/tests/Feature/Auth/AuthenticationTest.php index 694ee85..329226d 100644 --- a/tests/Feature/Auth/AuthenticationTest.php +++ b/tests/Feature/Auth/AuthenticationTest.php @@ -34,9 +34,7 @@ public function test_users_can_authenticate_using_the_login_screen() public function test_users_with_two_factor_enabled_are_redirected_to_two_factor_challenge() { - if (! Features::canManageTwoFactorAuthentication()) { - $this->markTestSkipped('Two-factor authentication is not enabled.'); - } + $this->skipUnlessFortifyFeature(Features::twoFactorAuthentication()); Features::twoFactorAuthentication([ 'confirm' => true, diff --git a/tests/Feature/Auth/EmailVerificationTest.php b/tests/Feature/Auth/EmailVerificationTest.php index 5ec123a..dba8afa 100644 --- a/tests/Feature/Auth/EmailVerificationTest.php +++ b/tests/Feature/Auth/EmailVerificationTest.php @@ -7,12 +7,20 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\URL; +use Laravel\Fortify\Features; use Tests\TestCase; class EmailVerificationTest extends TestCase { use RefreshDatabase; + protected function setUp(): void + { + parent::setUp(); + + $this->skipUnlessFortifyFeature(Features::emailVerification()); + } + public function test_email_verification_screen_can_be_rendered() { $user = User::factory()->unverified()->create(); diff --git a/tests/Feature/Auth/PasswordResetTest.php b/tests/Feature/Auth/PasswordResetTest.php index 227dfad..f29c53d 100644 --- a/tests/Feature/Auth/PasswordResetTest.php +++ b/tests/Feature/Auth/PasswordResetTest.php @@ -6,12 +6,20 @@ use Illuminate\Auth\Notifications\ResetPassword; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Notification; +use Laravel\Fortify\Features; use Tests\TestCase; class PasswordResetTest extends TestCase { use RefreshDatabase; + protected function setUp(): void + { + parent::setUp(); + + $this->skipUnlessFortifyFeature(Features::resetPasswords()); + } + public function test_reset_password_link_screen_can_be_rendered() { $response = $this->get(route('password.request')); diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 331076d..e25a94b 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -3,12 +3,20 @@ namespace Tests\Feature\Auth; use Illuminate\Foundation\Testing\RefreshDatabase; +use Laravel\Fortify\Features; use Tests\TestCase; class RegistrationTest extends TestCase { use RefreshDatabase; + protected function setUp(): void + { + parent::setUp(); + + $this->skipUnlessFortifyFeature(Features::registration()); + } + public function test_registration_screen_can_be_rendered() { $response = $this->get(route('register')); diff --git a/tests/Feature/Auth/TwoFactorChallengeTest.php b/tests/Feature/Auth/TwoFactorChallengeTest.php index 599c79f..f1c1c80 100644 --- a/tests/Feature/Auth/TwoFactorChallengeTest.php +++ b/tests/Feature/Auth/TwoFactorChallengeTest.php @@ -12,12 +12,15 @@ class TwoFactorChallengeTest extends TestCase { use RefreshDatabase; - public function test_two_factor_challenge_redirects_to_login_when_not_authenticated(): void + protected function setUp(): void { - if (! Features::canManageTwoFactorAuthentication()) { - $this->markTestSkipped('Two-factor authentication is not enabled.'); - } + parent::setUp(); + + $this->skipUnlessFortifyFeature(Features::twoFactorAuthentication()); + } + public function test_two_factor_challenge_redirects_to_login_when_not_authenticated(): void + { $response = $this->get(route('two-factor.login')); $response->assertRedirect(route('login')); @@ -25,10 +28,6 @@ public function test_two_factor_challenge_redirects_to_login_when_not_authentica public function test_two_factor_challenge_can_be_rendered(): void { - if (! Features::canManageTwoFactorAuthentication()) { - $this->markTestSkipped('Two-factor authentication is not enabled.'); - } - Features::twoFactorAuthentication([ 'confirm' => true, 'confirmPassword' => true, diff --git a/tests/Feature/Auth/VerificationNotificationTest.php b/tests/Feature/Auth/VerificationNotificationTest.php index cfd8861..389b537 100644 --- a/tests/Feature/Auth/VerificationNotificationTest.php +++ b/tests/Feature/Auth/VerificationNotificationTest.php @@ -6,12 +6,20 @@ use Illuminate\Auth\Notifications\VerifyEmail; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Notification; +use Laravel\Fortify\Features; use Tests\TestCase; class VerificationNotificationTest extends TestCase { use RefreshDatabase; + protected function setUp(): void + { + parent::setUp(); + + $this->skipUnlessFortifyFeature(Features::emailVerification()); + } + public function test_sends_verification_notification(): void { Notification::fake(); diff --git a/tests/Feature/Settings/TwoFactorAuthenticationTest.php b/tests/Feature/Settings/TwoFactorAuthenticationTest.php index 7a71d8a..8822448 100644 --- a/tests/Feature/Settings/TwoFactorAuthenticationTest.php +++ b/tests/Feature/Settings/TwoFactorAuthenticationTest.php @@ -14,9 +14,7 @@ class TwoFactorAuthenticationTest extends TestCase public function test_two_factor_settings_page_can_be_rendered() { - if (! Features::canManageTwoFactorAuthentication()) { - $this->markTestSkipped('Two-factor authentication is not enabled.'); - } + $this->skipUnlessFortifyFeature(Features::twoFactorAuthentication()); Features::twoFactorAuthentication([ 'confirm' => true, @@ -36,9 +34,7 @@ public function test_two_factor_settings_page_can_be_rendered() public function test_two_factor_settings_page_requires_password_confirmation_when_enabled() { - if (! Features::canManageTwoFactorAuthentication()) { - $this->markTestSkipped('Two-factor authentication is not enabled.'); - } + $this->skipUnlessFortifyFeature(Features::twoFactorAuthentication()); $user = User::factory()->create(); @@ -55,9 +51,7 @@ public function test_two_factor_settings_page_requires_password_confirmation_whe public function test_two_factor_settings_page_does_not_requires_password_confirmation_when_disabled() { - if (! Features::canManageTwoFactorAuthentication()) { - $this->markTestSkipped('Two-factor authentication is not enabled.'); - } + $this->skipUnlessFortifyFeature(Features::twoFactorAuthentication()); $user = User::factory()->create(); @@ -76,9 +70,7 @@ public function test_two_factor_settings_page_does_not_requires_password_confirm public function test_two_factor_settings_page_returns_forbidden_response_when_two_factor_is_disabled() { - if (! Features::canManageTwoFactorAuthentication()) { - $this->markTestSkipped('Two-factor authentication is not enabled.'); - } + $this->skipUnlessFortifyFeature(Features::twoFactorAuthentication()); config(['fortify.features' => []]); diff --git a/tests/TestCase.php b/tests/TestCase.php index fe1ffc2..3399054 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -3,8 +3,14 @@ namespace Tests; use Illuminate\Foundation\Testing\TestCase as BaseTestCase; +use Laravel\Fortify\Features; abstract class TestCase extends BaseTestCase { - // + protected function skipUnlessFortifyFeature(string $feature, ?string $message = null): void + { + if (! Features::enabled($feature)) { + $this->markTestSkipped($message ?? "Fortify feature [{$feature}] is not enabled."); + } + } }