-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdoSessionHandlerTest.php
More file actions
77 lines (64 loc) · 2.06 KB
/
Copy pathPdoSessionHandlerTest.php
File metadata and controls
77 lines (64 loc) · 2.06 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
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Detain\SessionSamuraiTest;
use PHPUnit\Framework\TestCase;
use Detain\SessionSamurai\PDOSessionHandler;
class PdoSessionHandlerTest extends TestCase
{
private PDOSessionHandler $handler;
private \PDO $pdo;
public function setUp(): void
{
$this->pdo = new \PDO('sqlite::memory:');
$this->pdo->exec('CREATE TABLE sessions (id TEXT PRIMARY KEY, data TEXT, updated_at INTEGER)');
$this->handler = new PDOSessionHandler($this->pdo);
}
public function testOpen()
{
$this->assertTrue($this->handler->open('', 'PHPSESSID'));
}
public function testClose()
{
$this->assertTrue($this->handler->close());
}
public function testReadEmpty()
{
$this->assertSame('', $this->handler->read('nonexistent'));
}
public function testWrite()
{
$key = $this->handler->create_sid();
$this->assertTrue($this->handler->write($key, 'my test data'));
}
public function testWriteRead()
{
$data = 'my test data';
$key = $this->handler->create_sid();
$this->handler->write($key, $data);
$this->assertSame($data, $this->handler->read($key));
}
public function testDestroy()
{
$key = $this->handler->create_sid();
$this->handler->write($key, 'data');
$this->assertTrue($this->handler->destroy($key));
$this->assertSame('', $this->handler->read($key));
}
public function testGc()
{
$key = $this->handler->create_sid();
$this->handler->write($key, 'data');
$this->assertNotFalse($this->handler->gc(0));
}
public function testUpdateTimestamp()
{
$key = $this->handler->create_sid();
$this->handler->write($key, 'data');
$this->assertTrue($this->handler->updateTimestamp($key, 'data'));
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function testCreate_sid()
{
$sid = $this->handler->create_sid();
$this->assertMatchesRegularExpression('/^[a-f0-9]{64}$/', $sid);
}
}