From 4dd37a065e208796d33ee49821670d119f2e4088 Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 12 Dec 2025 09:56:54 +0100 Subject: [PATCH 1/6] wip --- packages/router/src/HttpApplication.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/router/src/HttpApplication.php b/packages/router/src/HttpApplication.php index 78b6e6961..d4e1f1c2a 100644 --- a/packages/router/src/HttpApplication.php +++ b/packages/router/src/HttpApplication.php @@ -10,7 +10,7 @@ use Tempest\Core\Kernel; use Tempest\Core\Tempest; use Tempest\Http\RequestFactory; -use Tempest\Http\Session\SessionManager; +use Tempest\Http\Session\Session; use Tempest\Log\Channels\AppendLogChannel; use Tempest\Log\LogConfig; @@ -57,7 +57,7 @@ public function run(): void $router->dispatch($psrRequest), ); - $this->container->get(SessionManager::class)->cleanup(); + $this->container->get(Session::class)->cleanup(); $this->container->get(Kernel::class)->shutdown(); } From 50b7f9782cd7ff9a77d4a88be585e7582a1950a3 Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 12 Dec 2025 10:22:49 +0100 Subject: [PATCH 2/6] wip --- .../Controllers/ControllerWithSession.php | 18 ++++++++++ .../Controllers/ControllerWithoutSession.php | 16 +++++++++ .../Application/HttpApplicationTest.php | 33 +++++++++++++++++++ tests/Integration/Http/RedisSessionTest.php | 4 +++ 4 files changed, 71 insertions(+) create mode 100644 tests/Fixtures/Controllers/ControllerWithSession.php create mode 100644 tests/Fixtures/Controllers/ControllerWithoutSession.php diff --git a/tests/Fixtures/Controllers/ControllerWithSession.php b/tests/Fixtures/Controllers/ControllerWithSession.php new file mode 100644 index 000000000..7fc9c6816 --- /dev/null +++ b/tests/Fixtures/Controllers/ControllerWithSession.php @@ -0,0 +1,18 @@ +flash('test', 'hi'); + + return new Ok(); + } +} \ No newline at end of file diff --git a/tests/Fixtures/Controllers/ControllerWithoutSession.php b/tests/Fixtures/Controllers/ControllerWithoutSession.php new file mode 100644 index 000000000..4fa05371e --- /dev/null +++ b/tests/Fixtures/Controllers/ControllerWithoutSession.php @@ -0,0 +1,16 @@ +get('/') ->assertOk(); } + + #[Test] + public function session_is_only_cleaned_when_started(): void + { + $this->appConfig->baseUri = 'http://127.0.0.1:8081'; + $process = new Process(['./tempest', 'serve', '127.0.0.1:8081'], getcwd()); + $process->start(); + usleep(200_000); + + $client = $this->get(HttpClient::class); + + $response = $client->get(uri(ControllerWithoutSession::class)); + $cookies = arr($response->getHeader('set-cookie')->values ?? []) + ->map(fn (string $cookie) => explode('=', $cookie)[0] ?? null); + + $this->assertFalse($cookies->contains('tempest_session_id')); + + $response = $client->get(uri(ControllerWithSession::class)); + $cookies = arr($response->getHeader('set-cookie')->values ?? []) + ->map(fn (string $cookie) => explode('=', $cookie)[0] ?? null); + + $this->assertTrue($cookies->contains('tempest_session_id')); + + $process->stop(); + } } diff --git a/tests/Integration/Http/RedisSessionTest.php b/tests/Integration/Http/RedisSessionTest.php index a38292736..98c79e1c0 100644 --- a/tests/Integration/Http/RedisSessionTest.php +++ b/tests/Integration/Http/RedisSessionTest.php @@ -29,6 +29,10 @@ protected function setUp(): void { parent::setUp(); + if (! extension_loaded('redis') || ! class_exists(\Redis::class)) { + $this->markTestSkipped('The `redis` extension is not loaded.'); + } + $this->container->config(new RedisSessionConfig(expiration: Duration::hours(2), prefix: 'test_session:')); $this->container->singleton( SessionManager::class, From 9c40b1fcd2ab6c99763006415bc78937d3ed0929 Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 12 Dec 2025 10:24:03 +0100 Subject: [PATCH 3/6] wip --- tests/Integration/Application/HttpApplicationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Integration/Application/HttpApplicationTest.php b/tests/Integration/Application/HttpApplicationTest.php index 19a97c2f4..4792a9011 100644 --- a/tests/Integration/Application/HttpApplicationTest.php +++ b/tests/Integration/Application/HttpApplicationTest.php @@ -27,7 +27,7 @@ public function test_http_application_run(): void } #[Test] - public function session_is_only_cleaned_when_started(): void + public function session_is_not_set_even_when_it_was_cleaned_and_empty(): void { $this->appConfig->baseUri = 'http://127.0.0.1:8081'; $process = new Process(['./tempest', 'serve', '127.0.0.1:8081'], getcwd()); From 322af8b7edcb5307388bd30ebe778850faf753bd Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 12 Dec 2025 10:24:20 +0100 Subject: [PATCH 4/6] wip --- tests/Integration/Application/HttpApplicationTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/Integration/Application/HttpApplicationTest.php b/tests/Integration/Application/HttpApplicationTest.php index 4792a9011..37d2e7985 100644 --- a/tests/Integration/Application/HttpApplicationTest.php +++ b/tests/Integration/Application/HttpApplicationTest.php @@ -6,7 +6,6 @@ use PHPUnit\Framework\Attributes\Test; use Symfony\Component\Process\Process; -use Tempest\Http\Session\Session; use Tempest\HttpClient\HttpClient; use Tests\Tempest\Fixtures\Controllers\ControllerWithoutSession; use Tests\Tempest\Fixtures\Controllers\ControllerWithSession; From 218b35abb28eaeebb796421aacb4b33f20b4dac1 Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 12 Dec 2025 10:24:27 +0100 Subject: [PATCH 5/6] wip --- tests/Fixtures/Controllers/ControllerWithSession.php | 2 +- tests/Fixtures/Controllers/ControllerWithoutSession.php | 2 +- tests/Integration/Application/HttpApplicationTest.php | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Fixtures/Controllers/ControllerWithSession.php b/tests/Fixtures/Controllers/ControllerWithSession.php index 7fc9c6816..d192bab6d 100644 --- a/tests/Fixtures/Controllers/ControllerWithSession.php +++ b/tests/Fixtures/Controllers/ControllerWithSession.php @@ -15,4 +15,4 @@ public function __invoke(Session $session): Ok return new Ok(); } -} \ No newline at end of file +} diff --git a/tests/Fixtures/Controllers/ControllerWithoutSession.php b/tests/Fixtures/Controllers/ControllerWithoutSession.php index 4fa05371e..b04732bb5 100644 --- a/tests/Fixtures/Controllers/ControllerWithoutSession.php +++ b/tests/Fixtures/Controllers/ControllerWithoutSession.php @@ -13,4 +13,4 @@ public function __invoke(): Ok { return new Ok(); } -} \ No newline at end of file +} diff --git a/tests/Integration/Application/HttpApplicationTest.php b/tests/Integration/Application/HttpApplicationTest.php index 37d2e7985..bf4f53ba3 100644 --- a/tests/Integration/Application/HttpApplicationTest.php +++ b/tests/Integration/Application/HttpApplicationTest.php @@ -10,6 +10,7 @@ use Tests\Tempest\Fixtures\Controllers\ControllerWithoutSession; use Tests\Tempest\Fixtures\Controllers\ControllerWithSession; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; + use function Tempest\Router\uri; use function Tempest\Support\arr; From cc2cc051c74a0f06e447a90a0018a82986bdc8dc Mon Sep 17 00:00:00 2001 From: brendt Date: Fri, 12 Dec 2025 10:29:14 +0100 Subject: [PATCH 6/6] wip --- tests/Integration/Application/HttpApplicationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Integration/Application/HttpApplicationTest.php b/tests/Integration/Application/HttpApplicationTest.php index bf4f53ba3..1112b9d15 100644 --- a/tests/Integration/Application/HttpApplicationTest.php +++ b/tests/Integration/Application/HttpApplicationTest.php @@ -38,13 +38,13 @@ public function session_is_not_set_even_when_it_was_cleaned_and_empty(): void $response = $client->get(uri(ControllerWithoutSession::class)); $cookies = arr($response->getHeader('set-cookie')->values ?? []) - ->map(fn (string $cookie) => explode('=', $cookie)[0] ?? null); + ->map(fn (string $cookie) => explode('=', $cookie)[0]); $this->assertFalse($cookies->contains('tempest_session_id')); $response = $client->get(uri(ControllerWithSession::class)); $cookies = arr($response->getHeader('set-cookie')->values ?? []) - ->map(fn (string $cookie) => explode('=', $cookie)[0] ?? null); + ->map(fn (string $cookie) => explode('=', $cookie)[0]); $this->assertTrue($cookies->contains('tempest_session_id'));