Skip to content

Commit 1c28331

Browse files
committed
test: cover session id resolution contexts
Signed-off-by: Vitor Mattos <[email protected]>
1 parent 2d3e22c commit 1c28331

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

tests/php/Unit/Service/SessionServiceTest.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,26 @@ private function getService(): SessionService {
3232
}
3333

3434
#[DataProvider('providerGetSessionId')]
35-
public function testGetSessionIdUsesUuidWhenAvailable(mixed $uuidInSession, string $sessionId, string $expected): void {
35+
public function testGetSessionIdResolvesByContext(?string $userId, mixed $uuid, string $expected): void {
3636
$this->session->method('get')
37-
->with('libresign-uuid')
38-
->willReturn($uuidInSession);
37+
->willReturnCallback(function (string $key) use ($userId, $uuid) {
38+
return match ($key) {
39+
'user_id' => $userId,
40+
'libresign-uuid' => $uuid,
41+
default => null,
42+
};
43+
});
3944
$this->session->method('getId')
40-
->willReturn($sessionId);
45+
->willReturn('session-raw-id');
4146

4247
$this->assertSame($expected, $this->getService()->getSessionId());
4348
}
4449

4550
public static function providerGetSessionId(): array {
4651
return [
47-
'uuid string present' => ['54afbd0a-a065-4eaf-b611-48ec381b116a', 'session-123', '54afbd0a-a065-4eaf-b611-48ec381b116a'],
48-
'uuid empty string' => ['', 'session-123', 'session-123'],
49-
'uuid null' => [null, 'session-123', 'session-123'],
50-
'uuid non-string' => [123, 'session-123', 'session-123'],
52+
'authenticated keeps raw session id' => ['admin', 'public-uuid', 'session-raw-id'],
53+
'anonymous uses public uuid when available' => [null, 'public-uuid', 'public-uuid'],
54+
'anonymous falls back to raw session id' => [null, null, 'session-raw-id'],
5155
];
5256
}
5357
}

0 commit comments

Comments
 (0)