-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSemaphoreSessionHandlerTest.php
More file actions
64 lines (52 loc) · 1.74 KB
/
Copy pathSemaphoreSessionHandlerTest.php
File metadata and controls
64 lines (52 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
namespace Detain\SessionSamuraiTest;
use PHPUnit\Framework\TestCase;
use Detain\SessionSamurai\SemaphoreSessionHandler;
class SemaphoreSessionHandlerTest extends TestCase
{
private SemaphoreSessionHandler $sessionHandler;
private string $sessionId;
public function setUp(): void
{
$this->sessionHandler = new SemaphoreSessionHandler();
$this->sessionId = $this->sessionHandler->create_sid();
}
public function testOpen()
{
$this->assertTrue($this->sessionHandler->open('test', 'PHPSESSID'));
}
public function testClose()
{
$this->assertTrue($this->sessionHandler->close());
}
public function testReadEmpty()
{
$this->assertSame('', $this->sessionHandler->read($this->sessionId));
}
public function testWrite()
{
$value = 'hello world';
$this->assertTrue($this->sessionHandler->write($this->sessionId, $value));
$this->assertEquals($value, $this->sessionHandler->read($this->sessionId));
}
public function testDestroy()
{
$this->sessionHandler->write($this->sessionId, 'data');
$this->assertTrue($this->sessionHandler->destroy($this->sessionId));
}
public function testGc()
{
$this->assertNotFalse($this->sessionHandler->gc(3600));
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function testCreate_sid()
{
$sid = $this->sessionHandler->create_sid();
$this->assertMatchesRegularExpression('/^[a-f0-9]{64}$/', $sid);
}
public function testUpdateTimestamp()
{
$this->sessionHandler->write($this->sessionId, 'data');
$this->assertTrue($this->sessionHandler->updateTimestamp($this->sessionId, 'data'));
}
}