Install Pest

This commit is contained in:
Bob Molitor
2025-10-16 14:22:58 +02:00
parent 81a98dd9f4
commit e8db0d9a5a
16 changed files with 1618 additions and 805 deletions
+1 -1
View File
@@ -51,4 +51,4 @@ jobs:
run: npm run build
- name: Run Tests
run: ./vendor/bin/phpunit
run: ./vendor/bin/pest
+2 -1
View File
@@ -23,7 +23,8 @@
"laravel/sail": "^1.41",
"mockery/mockery": "^1.6",
"nunomaduro/collision": "^8.6",
"phpunit/phpunit": "^11.5.3"
"pestphp/pest": "^4.1",
"pestphp/pest-plugin-laravel": "^4.0"
},
"autoload": {
"psr-4": {
Generated
+1227 -316
View File
File diff suppressed because it is too large Load Diff
+59 -73
View File
@@ -1,91 +1,77 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Livewire\Volt\Volt as LivewireVolt;
use Tests\TestCase;
class AuthenticationTest extends TestCase
{
use RefreshDatabase;
test('login screen can be rendered', function () {
$response = $this->get(route('login'));
public function test_login_screen_can_be_rendered(): void
{
$response = $this->get(route('login'));
$response->assertStatus(200);
});
$response->assertStatus(200);
test('users can authenticate using the login screen', function () {
$user = User::factory()->withoutTwoFactor()->create();
$response = LivewireVolt::test('auth.login')
->set('email', $user->email)
->set('password', 'password')
->call('login');
$response
->assertHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();
});
test('users can not authenticate with invalid password', function () {
$user = User::factory()->create();
$response = LivewireVolt::test('auth.login')
->set('email', $user->email)
->set('password', 'wrong-password')
->call('login');
$response->assertHasErrors('email');
$this->assertGuest();
});
test('users with two factor enabled are redirected to two factor challenge', function () {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
public function test_users_can_authenticate_using_the_login_screen(): void
{
$user = User::factory()->withoutTwoFactor()->create();
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$response = LivewireVolt::test('auth.login')
->set('email', $user->email)
->set('password', 'password')
->call('login');
$user = User::factory()->create();
$response
->assertHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$user->forceFill([
'two_factor_secret' => encrypt('test-secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
'two_factor_confirmed_at' => now(),
])->save();
$this->assertAuthenticated();
}
$response = LivewireVolt::test('auth.login')
->set('email', $user->email)
->set('password', 'password')
->call('login');
public function test_users_can_not_authenticate_with_invalid_password(): void
{
$user = User::factory()->create();
$response->assertRedirect(route('two-factor.login'));
$response->assertSessionHas('login.id', $user->id);
$this->assertGuest();
});
$response = LivewireVolt::test('auth.login')
->set('email', $user->email)
->set('password', 'wrong-password')
->call('login');
test('users can logout', function () {
$user = User::factory()->create();
$response->assertHasErrors('email');
$response = $this->actingAs($user)->post(route('logout'));
$this->assertGuest();
}
$response->assertRedirect(route('home'));
public function test_users_with_two_factor_enabled_are_redirected_to_two_factor_challenge(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$user = User::factory()->create();
$user->forceFill([
'two_factor_secret' => encrypt('test-secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
'two_factor_confirmed_at' => now(),
])->save();
$response = LivewireVolt::test('auth.login')
->set('email', $user->email)
->set('password', 'password')
->call('login');
$response->assertRedirect(route('two-factor.login'));
$response->assertSessionHas('login.id', $user->id);
$this->assertGuest();
}
public function test_users_can_logout(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->post(route('logout'));
$response->assertRedirect(route('home'));
$this->assertGuest();
}
}
$this->assertGuest();
});
+43 -56
View File
@@ -1,80 +1,67 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Events\Verified;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\URL;
use Tests\TestCase;
class EmailVerificationTest extends TestCase
{
use RefreshDatabase;
test('email verification screen can be rendered', function () {
$user = User::factory()->unverified()->create();
public function test_email_verification_screen_can_be_rendered(): void
{
$user = User::factory()->unverified()->create();
$response = $this->actingAs($user)->get(route('verification.notice'));
$response = $this->actingAs($user)->get(route('verification.notice'));
$response->assertStatus(200);
});
$response->assertStatus(200);
}
test('email can be verified', function () {
$user = User::factory()->unverified()->create();
public function test_email_can_be_verified(): void
{
$user = User::factory()->unverified()->create();
Event::fake();
Event::fake();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$response = $this->actingAs($user)->get($verificationUrl);
$response = $this->actingAs($user)->get($verificationUrl);
Event::assertDispatched(Verified::class);
Event::assertDispatched(Verified::class);
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
});
$this->assertTrue($user->fresh()->hasVerifiedEmail());
$response->assertRedirect(route('dashboard', absolute: false).'?verified=1');
}
test('email is not verified with invalid hash', function () {
$user = User::factory()->unverified()->create();
public function test_email_is_not_verified_with_invalid_hash(): void
{
$user = User::factory()->unverified()->create();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1('wrong-email')]
);
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1('wrong-email')]
);
$this->actingAs($user)->get($verificationUrl);
$this->actingAs($user)->get($verificationUrl);
expect($user->fresh()->hasVerifiedEmail())->toBeFalse();
});
$this->assertFalse($user->fresh()->hasVerifiedEmail());
}
test('already verified user visiting verification link is redirected without firing event again', function () {
$user = User::factory()->create([
'email_verified_at' => now(),
]);
public function test_already_verified_user_visiting_verification_link_is_redirected_without_firing_event_again(): void
{
$user = User::factory()->create([
'email_verified_at' => now(),
]);
Event::fake();
Event::fake();
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$verificationUrl = URL::temporarySignedRoute(
'verification.verify',
now()->addMinutes(60),
['id' => $user->id, 'hash' => sha1($user->email)]
);
$this->actingAs($user)->get($verificationUrl)
->assertRedirect(route('dashboard', absolute: false).'?verified=1');
$this->actingAs($user)->get($verificationUrl)
->assertRedirect(route('dashboard', absolute: false).'?verified=1');
$this->assertTrue($user->fresh()->hasVerifiedEmail());
Event::assertNotDispatched(Verified::class);
}
}
expect($user->fresh()->hasVerifiedEmail())->toBeTrue();
Event::assertNotDispatched(Verified::class);
});
@@ -1,21 +1,11 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class PasswordConfirmationTest extends TestCase
{
use RefreshDatabase;
test('confirm password screen can be rendered', function () {
$user = User::factory()->create();
public function test_confirm_password_screen_can_be_rendered(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get(route('password.confirm'));
$response = $this->actingAs($user)->get(route('password.confirm'));
$response->assertStatus(200);
}
}
$response->assertStatus(200);
});
+50 -63
View File
@@ -1,79 +1,66 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Notification;
use Livewire\Volt\Volt;
use Tests\TestCase;
class PasswordResetTest extends TestCase
{
use RefreshDatabase;
test('reset password link screen can be rendered', function () {
$response = $this->get(route('password.request'));
public function test_reset_password_link_screen_can_be_rendered(): void
{
$response = $this->get(route('password.request'));
$response->assertStatus(200);
});
test('reset password link can be requested', function () {
Notification::fake();
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class);
});
test('reset password screen can be rendered', function () {
Notification::fake();
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
$response = $this->get(route('password.reset', $notification->token));
$response->assertStatus(200);
}
public function test_reset_password_link_can_be_requested(): void
{
Notification::fake();
return true;
});
});
$user = User::factory()->create();
test('password can be reset with valid token', function () {
Notification::fake();
Volt::test('auth.forgot-password')
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
$response = Volt::test('auth.reset-password', ['token' => $notification->token])
->set('email', $user->email)
->call('sendPasswordResetLink');
->set('password', 'password')
->set('password_confirmation', 'password')
->call('resetPassword');
Notification::assertSentTo($user, ResetPassword::class);
}
$response
->assertHasNoErrors()
->assertRedirect(route('login', absolute: false));
public function test_reset_password_screen_can_be_rendered(): void
{
Notification::fake();
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class, function ($notification) {
$response = $this->get(route('password.reset', $notification->token));
$response->assertStatus(200);
return true;
});
}
public function test_password_can_be_reset_with_valid_token(): void
{
Notification::fake();
$user = User::factory()->create();
Volt::test('auth.forgot-password')
->set('email', $user->email)
->call('sendPasswordResetLink');
Notification::assertSentTo($user, ResetPassword::class, function ($notification) use ($user) {
$response = Volt::test('auth.reset-password', ['token' => $notification->token])
->set('email', $user->email)
->set('password', 'password')
->set('password_confirmation', 'password')
->call('resetPassword');
$response
->assertHasNoErrors()
->assertRedirect(route('login', absolute: false));
return true;
});
}
}
return true;
});
});
+16 -27
View File
@@ -1,35 +1,24 @@
<?php
namespace Tests\Feature\Auth;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Volt\Volt;
use Tests\TestCase;
class RegistrationTest extends TestCase
{
use RefreshDatabase;
test('registration screen can be rendered', function () {
$response = $this->get(route('register'));
public function test_registration_screen_can_be_rendered(): void
{
$response = $this->get(route('register'));
$response->assertStatus(200);
});
$response->assertStatus(200);
}
test('new users can register', function () {
$response = Volt::test('auth.register')
->set('name', 'Test User')
->set('email', 'test@example.com')
->set('password', 'password')
->set('password_confirmation', 'password')
->call('register');
public function test_new_users_can_register(): void
{
$response = Volt::test('auth.register')
->set('name', 'Test User')
->set('email', 'test@example.com')
->set('password', 'password')
->set('password_confirmation', 'password')
->call('register');
$response
->assertHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$response
->assertHasNoErrors()
->assertRedirect(route('dashboard', absolute: false));
$this->assertAuthenticated();
}
}
$this->assertAuthenticated();
});
+30 -41
View File
@@ -1,52 +1,41 @@
<?php
namespace Tests\Feature\Auth;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Livewire\Volt\Volt;
use Tests\TestCase;
class TwoFactorChallengeTest extends TestCase
{
use RefreshDatabase;
public function test_two_factor_challenge_redirects_to_login_when_not_authenticated(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
$response = $this->get(route('two-factor.login'));
$response->assertRedirect(route('login'));
test('two factor challenge redirects to login when not authenticated', function () {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
public function test_two_factor_challenge_can_be_rendered(): void
{
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
$response = $this->get(route('two-factor.login'));
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$response->assertRedirect(route('login'));
});
$user = User::factory()->create();
$user->forceFill([
'two_factor_secret' => encrypt('test-secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
'two_factor_confirmed_at' => now(),
])->save();
Volt::test('auth.login')
->set('email', $user->email)
->set('password', 'password')
->call('login')
->assertRedirect(route('two-factor.login'))
->assertOk();
test('two factor challenge can be rendered', function () {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
}
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
$user = User::factory()->create();
$user->forceFill([
'two_factor_secret' => encrypt('test-secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
'two_factor_confirmed_at' => now(),
])->save();
Volt::test('auth.login')
->set('email', $user->email)
->set('password', 'password')
->call('login')
->assertRedirect(route('two-factor.login'))
->assertOk();
});
+10 -21
View File
@@ -1,27 +1,16 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DashboardTest extends TestCase
{
use RefreshDatabase;
test('guests are redirected to the login page', function () {
$response = $this->get(route('dashboard'));
$response->assertRedirect(route('login'));
});
public function test_guests_are_redirected_to_the_login_page(): void
{
$response = $this->get(route('dashboard'));
$response->assertRedirect(route('login'));
}
test('authenticated users can visit the dashboard', function () {
$user = User::factory()->create();
$this->actingAs($user);
public function test_authenticated_users_can_visit_the_dashboard(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$response = $this->get(route('dashboard'));
$response->assertStatus(200);
}
}
$response = $this->get(route('dashboard'));
$response->assertStatus(200);
});
+4 -15
View File
@@ -1,18 +1,7 @@
<?php
namespace Tests\Feature;
test('returns a successful response', function () {
$response = $this->get(route('home'));
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
public function test_returns_a_successful_response(): void
{
$response = $this->get(route('home'));
$response->assertStatus(200);
}
}
$response->assertStatus(200);
});
+25 -36
View File
@@ -1,50 +1,39 @@
<?php
namespace Tests\Feature\Settings;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Hash;
use Livewire\Volt\Volt;
use Tests\TestCase;
class PasswordUpdateTest extends TestCase
{
use RefreshDatabase;
test('password can be updated', function () {
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
public function test_password_can_be_updated(): void
{
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
$this->actingAs($user);
$this->actingAs($user);
$response = Volt::test('settings.password')
->set('current_password', 'password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$response = Volt::test('settings.password')
->set('current_password', 'password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$response->assertHasNoErrors();
$response->assertHasNoErrors();
expect(Hash::check('new-password', $user->refresh()->password))->toBeTrue();
});
$this->assertTrue(Hash::check('new-password', $user->refresh()->password));
}
test('correct password must be provided to update password', function () {
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
public function test_correct_password_must_be_provided_to_update_password(): void
{
$user = User::factory()->create([
'password' => Hash::make('password'),
]);
$this->actingAs($user);
$this->actingAs($user);
$response = Volt::test('settings.password')
->set('current_password', 'wrong-password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$response = Volt::test('settings.password')
->set('current_password', 'wrong-password')
->set('password', 'new-password')
->set('password_confirmation', 'new-password')
->call('updatePassword');
$response->assertHasErrors(['current_password']);
}
}
$response->assertHasErrors(['current_password']);
});
+48 -62
View File
@@ -1,89 +1,75 @@
<?php
namespace Tests\Feature\Settings;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Volt\Volt;
use Tests\TestCase;
class ProfileUpdateTest extends TestCase
{
use RefreshDatabase;
test('profile page is displayed', function () {
$this->actingAs($user = User::factory()->create());
public function test_profile_page_is_displayed(): void
{
$this->actingAs($user = User::factory()->create());
$this->get(route('profile.edit'))->assertOk();
});
$this->get(route('profile.edit'))->assertOk();
}
test('profile information can be updated', function () {
$user = User::factory()->create();
public function test_profile_information_can_be_updated(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$this->actingAs($user);
$response = Volt::test('settings.profile')
->set('name', 'Test User')
->set('email', 'test@example.com')
->call('updateProfileInformation');
$response = Volt::test('settings.profile')
->set('name', 'Test User')
->set('email', 'test@example.com')
->call('updateProfileInformation');
$response->assertHasNoErrors();
$response->assertHasNoErrors();
$user->refresh();
$user->refresh();
expect($user->name)->toEqual('Test User');
expect($user->email)->toEqual('test@example.com');
expect($user->email_verified_at)->toBeNull();
});
$this->assertEquals('Test User', $user->name);
$this->assertEquals('test@example.com', $user->email);
$this->assertNull($user->email_verified_at);
}
test('email verification status is unchanged when email address is unchanged', function () {
$user = User::factory()->create();
public function test_email_verification_status_is_unchanged_when_email_address_is_unchanged(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$this->actingAs($user);
$response = Volt::test('settings.profile')
->set('name', 'Test User')
->set('email', $user->email)
->call('updateProfileInformation');
$response = Volt::test('settings.profile')
->set('name', 'Test User')
->set('email', $user->email)
->call('updateProfileInformation');
$response->assertHasNoErrors();
$response->assertHasNoErrors();
expect($user->refresh()->email_verified_at)->not->toBeNull();
});
$this->assertNotNull($user->refresh()->email_verified_at);
}
test('user can delete their account', function () {
$user = User::factory()->create();
public function test_user_can_delete_their_account(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$this->actingAs($user);
$response = Volt::test('settings.delete-user-form')
->set('password', 'password')
->call('deleteUser');
$response = Volt::test('settings.delete-user-form')
->set('password', 'password')
->call('deleteUser');
$response
->assertHasNoErrors()
->assertRedirect('/');
$response
->assertHasNoErrors()
->assertRedirect('/');
expect($user->fresh())->toBeNull();
expect(auth()->check())->toBeFalse();
});
$this->assertNull($user->fresh());
$this->assertFalse(auth()->check());
}
test('correct password must be provided to delete account', function () {
$user = User::factory()->create();
public function test_correct_password_must_be_provided_to_delete_account(): void
{
$user = User::factory()->create();
$this->actingAs($user);
$this->actingAs($user);
$response = Volt::test('settings.delete-user-form')
->set('password', 'wrong-password')
->call('deleteUser');
$response = Volt::test('settings.delete-user-form')
->set('password', 'wrong-password')
->call('deleteUser');
$response->assertHasErrors(['password']);
$response->assertHasErrors(['password']);
$this->assertNotNull($user->fresh());
}
}
expect($user->fresh())->not->toBeNull();
});
@@ -1,86 +1,70 @@
<?php
namespace Tests\Feature\Settings;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Laravel\Fortify\Features;
use Livewire\Volt\Volt;
use Tests\TestCase;
class TwoFactorAuthenticationTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
beforeEach(function () {
if (! Features::canManageTwoFactorAuthentication()) {
$this->markTestSkipped('Two-factor authentication is not enabled.');
}
public function test_two_factor_settings_page_can_be_rendered(): void
{
$user = User::factory()->withoutTwoFactor()->create();
Features::twoFactorAuthentication([
'confirm' => true,
'confirmPassword' => true,
]);
});
$this->actingAs($user)
->withSession(['auth.password_confirmed_at' => time()])
->get(route('two-factor.show'))
->assertOk()
->assertSee('Two Factor Authentication')
->assertSee('Disabled');
}
test('two factor settings page can be rendered', function () {
$user = User::factory()->withoutTwoFactor()->create();
public function test_two_factor_settings_page_requires_password_confirmation_when_enabled(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->withSession(['auth.password_confirmed_at' => time()])
->get(route('two-factor.show'))
->assertOk()
->assertSee('Two Factor Authentication')
->assertSee('Disabled');
});
$response = $this->actingAs($user)
->get(route('two-factor.show'));
test('two factor settings page requires password confirmation when enabled', function () {
$user = User::factory()->create();
$response->assertRedirect(route('password.confirm'));
}
$response = $this->actingAs($user)
->get(route('two-factor.show'));
public function test_two_factor_settings_page_returns_forbidden_response_when_two_factor_is_disabled(): void
{
config(['fortify.features' => []]);
$response->assertRedirect(route('password.confirm'));
});
$user = User::factory()->create();
test('two factor settings page returns forbidden response when two factor is disabled', function () {
config(['fortify.features' => []]);
$response = $this->actingAs($user)
->withSession(['auth.password_confirmed_at' => time()])
->get(route('two-factor.show'));
$user = User::factory()->create();
$response->assertForbidden();
}
$response = $this->actingAs($user)
->withSession(['auth.password_confirmed_at' => time()])
->get(route('two-factor.show'));
public function test_two_factor_authentication_disabled_when_confirmation_abandoned_between_requests(): void
{
$user = User::factory()->create();
$response->assertForbidden();
});
$user->forceFill([
'two_factor_secret' => encrypt('test-secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
'two_factor_confirmed_at' => null,
])->save();
test('two factor authentication disabled when confirmation abandoned between requests', function () {
$user = User::factory()->create();
$this->actingAs($user);
$user->forceFill([
'two_factor_secret' => encrypt('test-secret'),
'two_factor_recovery_codes' => encrypt(json_encode(['code1', 'code2'])),
'two_factor_confirmed_at' => null,
])->save();
$component = Volt::test('settings.two-factor');
$this->actingAs($user);
$component->assertSet('twoFactorEnabled', false);
$component = Volt::test('settings.two-factor');
$this->assertDatabaseHas('users', [
'id' => $user->id,
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,
]);
}
}
$component->assertSet('twoFactorEnabled', false);
$this->assertDatabaseHas('users', [
'id' => $user->id,
'two_factor_secret' => null,
'two_factor_recovery_codes' => null,
]);
});
+47
View File
@@ -0,0 +1,47 @@
<?php
/*
|--------------------------------------------------------------------------
| Test Case
|--------------------------------------------------------------------------
|
| The closure you provide to your test functions is always bound to a specific PHPUnit test
| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
| need to change it using the "pest()" function to bind a different classes or traits.
|
*/
pest()->extend(Tests\TestCase::class)
->use(Illuminate\Foundation\Testing\RefreshDatabase::class)
->in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something()
{
// ..
}
+3 -14
View File
@@ -1,16 +1,5 @@
<?php
namespace Tests\Unit;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
use RefreshDatabase;
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}
test('that true is true', function () {
expect(true)->toBeTrue();
});