set('name', 'Test User') ->set('email', 'testuser@example.com') ->set('password', 'correct-horse-battery-staple') ->set('password_confirmation', 'correct-horse-battery-staple') ->call('register') ->assertRedirect(route('sites.index')); $this->assertAuthenticated(); $this->assertDatabaseHas('users', ['email' => 'testuser@example.com']); } public function test_a_user_can_log_in(): void { $user = User::factory()->create(['password' => 'correct-horse-battery-staple']); Livewire::test(Login::class) ->set('email', $user->email) ->set('password', 'correct-horse-battery-staple') ->call('login') ->assertRedirect(route('sites.index')); $this->assertAuthenticatedAs($user); } public function test_login_fails_with_wrong_password(): void { $user = User::factory()->create(['password' => 'correct-horse-battery-staple']); Livewire::test(Login::class) ->set('email', $user->email) ->set('password', 'wrong-password') ->call('login') ->assertHasErrors('email'); $this->assertGuest(); } public function test_a_user_can_log_out(): void { $user = User::factory()->create(); $this->actingAs($user) ->post(route('logout')) ->assertRedirect(route('home')); $this->assertGuest(); } }