From 5476900d32ca6826a4401b801cb330a0ea74acba Mon Sep 17 00:00:00 2001 From: brendt Date: Thu, 15 Jan 2026 12:49:46 +0100 Subject: [PATCH] wip --- .../Resolvers/HeaderSessionIdResolver.php | 2 ++ .../HeaderWithUnderscoresController.php | 16 ++++++++++++++++ ...rTest.php => HeaderSessionIdResolverTest.php} | 11 +++++++++-- tests/Integration/Route/RequestTest.php | 13 +++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/Fixtures/Controllers/HeaderWithUnderscoresController.php rename tests/Integration/Http/{SessionFromHeaderTest.php => HeaderSessionIdResolverTest.php} (77%) diff --git a/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php b/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php index bd2a272ea7..ecc26b7245 100644 --- a/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php +++ b/packages/http/src/Session/Resolvers/HeaderSessionIdResolver.php @@ -10,6 +10,8 @@ use Tempest\Http\Session\SessionId; use Tempest\Http\Session\SessionIdResolver; +use function Tempest\Support\str; + final readonly class HeaderSessionIdResolver implements SessionIdResolver { public function __construct( diff --git a/tests/Fixtures/Controllers/HeaderWithUnderscoresController.php b/tests/Fixtures/Controllers/HeaderWithUnderscoresController.php new file mode 100644 index 0000000000..a0616b99b2 --- /dev/null +++ b/tests/Fixtures/Controllers/HeaderWithUnderscoresController.php @@ -0,0 +1,16 @@ +addHeader('tempest_session_id', $request->headers->get('tempest_session_id')); + } +} diff --git a/tests/Integration/Http/SessionFromHeaderTest.php b/tests/Integration/Http/HeaderSessionIdResolverTest.php similarity index 77% rename from tests/Integration/Http/SessionFromHeaderTest.php rename to tests/Integration/Http/HeaderSessionIdResolverTest.php index adb9d3b5b7..41ffec6d44 100644 --- a/tests/Integration/Http/SessionFromHeaderTest.php +++ b/tests/Integration/Http/HeaderSessionIdResolverTest.php @@ -9,19 +9,26 @@ use Tempest\Http\Method; use Tempest\Http\Request; use Tempest\Http\Session\Config\FileSessionConfig; +use Tempest\Http\Session\Resolvers\HeaderSessionIdResolver; use Tempest\Http\Session\Session; +use Tempest\Http\Session\SessionIdResolver; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; /** * @internal */ -final class SessionFromHeaderTest extends FrameworkIntegrationTestCase +final class HeaderSessionIdResolverTest extends FrameworkIntegrationTestCase { public function test_resolving_session_from_header(): void { + $this->container->singleton( + SessionIdResolver::class, + $this->container->get(HeaderSessionIdResolver::class), + ); + $this->container->config(new FileSessionConfig( - path: 'test_sessions', expiration: Duration::hours(2), + path: 'test_sessions', )); $this->setSessionId('session_a'); diff --git a/tests/Integration/Route/RequestTest.php b/tests/Integration/Route/RequestTest.php index 5648c567c2..01d8f2357d 100644 --- a/tests/Integration/Route/RequestTest.php +++ b/tests/Integration/Route/RequestTest.php @@ -106,6 +106,19 @@ public function test_custom_request_test(): void $this->assertEquals('test-title test-text', $response->body); } + public function test_headers_with_underscores(): void + { + $this->http + ->get( + uri: '/header-with-underscores', + headers: [ + 'tempest_session_id' => 'test', + ], + ) + ->assertOk() + ->assertHeaderMatches('tempest_session_id', 'test'); + } + public function test_generic_request_can_map_to_custom_request(): void { $response = $this->http