|
7 | 7 | use Laminas\Diactoros\ServerRequest; |
8 | 8 | use Laminas\Diactoros\Stream; |
9 | 9 | use Laminas\Diactoros\Uri; |
| 10 | +use Tempest\Clock\Clock; |
10 | 11 | use Tempest\Database\Migrations\CreateMigrationsTable; |
11 | 12 | use Tempest\Http\ContentType; |
12 | 13 | use Tempest\Http\Responses\Ok; |
| 14 | +use Tempest\Http\Session\Session; |
| 15 | +use Tempest\Http\Session\SessionId; |
| 16 | +use Tempest\Http\Session\SessionManager; |
13 | 17 | use Tempest\Http\Status; |
14 | 18 | use Tempest\Router\GenericRouter; |
15 | 19 | use Tempest\Router\RouteConfig; |
@@ -260,6 +264,20 @@ public function test_stateless_decorator(): void |
260 | 264 | ->assertDoesNotHaveCookie('tempest_session_id'); |
261 | 265 | } |
262 | 266 |
|
| 267 | + public function test_stateless_decorator_does_not_manage_session(): void |
| 268 | + { |
| 269 | + $sessionManager = new RouteTestingSessionManager($this->container->get(Clock::class)); |
| 270 | + |
| 271 | + $this->container->singleton(SessionManager::class, fn () => $sessionManager); |
| 272 | + |
| 273 | + $this->http |
| 274 | + ->get('/stateless') |
| 275 | + ->assertOk(); |
| 276 | + |
| 277 | + $this->assertSame(0, $sessionManager->createdSessions); |
| 278 | + $this->assertSame(0, $sessionManager->savedSessions); |
| 279 | + } |
| 280 | + |
263 | 281 | public function test_prefix_decorator(): void |
264 | 282 | { |
265 | 283 | $this->http |
@@ -327,3 +345,41 @@ public function test_multiple_optional_parameters(): void |
327 | 345 | ->assertSee('Post 789 in category tech'); |
328 | 346 | } |
329 | 347 | } |
| 348 | + |
| 349 | +final class RouteTestingSessionManager implements SessionManager |
| 350 | +{ |
| 351 | + public int $createdSessions = 0; |
| 352 | + |
| 353 | + public int $savedSessions = 0; |
| 354 | + |
| 355 | + public function __construct( |
| 356 | + private readonly Clock $clock, |
| 357 | + ) {} |
| 358 | + |
| 359 | + public function getOrCreate(SessionId $id): Session |
| 360 | + { |
| 361 | + $this->createdSessions++; |
| 362 | + |
| 363 | + $now = $this->clock->now(); |
| 364 | + |
| 365 | + return new Session( |
| 366 | + id: $id, |
| 367 | + createdAt: $now, |
| 368 | + lastActiveAt: $now, |
| 369 | + ); |
| 370 | + } |
| 371 | + |
| 372 | + public function save(Session $session): void |
| 373 | + { |
| 374 | + $this->savedSessions++; |
| 375 | + } |
| 376 | + |
| 377 | + public function delete(Session $session): void {} |
| 378 | + |
| 379 | + public function isValid(Session $session): bool |
| 380 | + { |
| 381 | + return true; |
| 382 | + } |
| 383 | + |
| 384 | + public function deleteExpiredSessions(): void {} |
| 385 | +} |
0 commit comments