Skip to content

Commit 50b7f97

Browse files
committed
wip
1 parent 4dd37a0 commit 50b7f97

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Tests\Tempest\Fixtures\Controllers;
4+
5+
use Tempest\Http\Responses\Ok;
6+
use Tempest\Http\Session\Session;
7+
use Tempest\Router\Get;
8+
9+
final class ControllerWithSession
10+
{
11+
#[Get('/controller-with-session')]
12+
public function __invoke(Session $session): Ok
13+
{
14+
$session->flash('test', 'hi');
15+
16+
return new Ok();
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Tests\Tempest\Fixtures\Controllers;
4+
5+
use Tempest\Http\Responses\Ok;
6+
use Tempest\Router\Get;
7+
use Tempest\Router\Stateless;
8+
9+
final class ControllerWithoutSession
10+
{
11+
#[Stateless, Get('/controller-without-session')]
12+
public function __invoke(): Ok
13+
{
14+
return new Ok();
15+
}
16+
}

tests/Integration/Application/HttpApplicationTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44

55
namespace Tests\Tempest\Integration\Application;
66

7+
use PHPUnit\Framework\Attributes\Test;
8+
use Symfony\Component\Process\Process;
9+
use Tempest\Http\Session\Session;
10+
use Tempest\HttpClient\HttpClient;
11+
use Tests\Tempest\Fixtures\Controllers\ControllerWithoutSession;
12+
use Tests\Tempest\Fixtures\Controllers\ControllerWithSession;
713
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
14+
use function Tempest\Router\uri;
15+
use function Tempest\Support\arr;
816

917
/**
1018
* @internal
@@ -17,4 +25,29 @@ public function test_http_application_run(): void
1725
->get('/')
1826
->assertOk();
1927
}
28+
29+
#[Test]
30+
public function session_is_only_cleaned_when_started(): void
31+
{
32+
$this->appConfig->baseUri = 'http://127.0.0.1:8081';
33+
$process = new Process(['./tempest', 'serve', '127.0.0.1:8081'], getcwd());
34+
$process->start();
35+
usleep(200_000);
36+
37+
$client = $this->get(HttpClient::class);
38+
39+
$response = $client->get(uri(ControllerWithoutSession::class));
40+
$cookies = arr($response->getHeader('set-cookie')->values ?? [])
41+
->map(fn (string $cookie) => explode('=', $cookie)[0] ?? null);
42+
43+
$this->assertFalse($cookies->contains('tempest_session_id'));
44+
45+
$response = $client->get(uri(ControllerWithSession::class));
46+
$cookies = arr($response->getHeader('set-cookie')->values ?? [])
47+
->map(fn (string $cookie) => explode('=', $cookie)[0] ?? null);
48+
49+
$this->assertTrue($cookies->contains('tempest_session_id'));
50+
51+
$process->stop();
52+
}
2053
}

tests/Integration/Http/RedisSessionTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ protected function setUp(): void
2929
{
3030
parent::setUp();
3131

32+
if (! extension_loaded('redis') || ! class_exists(\Redis::class)) {
33+
$this->markTestSkipped('The `redis` extension is not loaded.');
34+
}
35+
3236
$this->container->config(new RedisSessionConfig(expiration: Duration::hours(2), prefix: 'test_session:'));
3337
$this->container->singleton(
3438
SessionManager::class,

0 commit comments

Comments
 (0)