create(new CreateUserDto( email: new EmailAddress('user@example.com'), passwordHash: 'hashed-password', )); app(SessionRepository::class)->create(new CreateSessionDto( token: 'session-token', user: $user, createdAt: $now, expiresAt: $now->modify('+7 days'), )); $response = $this->withCredentials() ->withUnencryptedCookie( AuthMiddleware::COOKIE_NAME, 'session-token', )->postJson('/api/logout'); $response->assertNoContent(); $response->assertCookieExpired(AuthMiddleware::COOKIE_NAME); $this->assertNull( app(SessionRepository::class)->findByToken('session-token'), ); } public function test_logout_rejects_a_request_without_a_cookie(): void { $response = $this->postJson('/api/logout'); $response ->assertStatus(401) ->assertExactJson(['error' => 'unauthenticated']); } }