create(['email' => 'admin@test.com', 'password' => bcrypt('password')]); $this->post('/login', [ 'email' => 'admin@test.com', 'password' => 'password', ])->assertRedirect('/admin/dashboard'); $this->assertAuthenticatedAs($admin); } public function test_unauthenticated_user_is_redirected_from_admin(): void { $this->get('/admin/dashboard')->assertRedirect('/login'); } public function test_non_admin_cannot_access_admin_routes(): void { $user = User::factory()->nonAdmin()->create(); $this->actingAs($user) ->get('/admin/dashboard') ->assertForbidden(); } public function test_admin_can_logout(): void { $admin = User::factory()->create(); $this->actingAs($admin) ->post('/logout') ->assertRedirect('/'); $this->assertGuest(); } }