-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemcachedSessionHandlerTest.php
More file actions
73 lines (60 loc) · 1.98 KB
/
Copy pathMemcachedSessionHandlerTest.php
File metadata and controls
73 lines (60 loc) · 1.98 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
<?php
namespace Detain\SessionSamuraiTest;
use Detain\SessionSamurai\MemcachedSessionHandler;
use PHPUnit\Framework\TestCase;
class MemcachedSessionHandlerTest extends TestCase
{
private \Memcached $memcached;
private MemcachedSessionHandler $handler;
public function setUp(): void
{
$this->memcached = $this->createMock(\Memcached::class);
$this->handler = new MemcachedSessionHandler($this->memcached);
$this->handler->open('', 'PHPSESSID');
}
public function testOpen()
{
$this->assertTrue($this->handler->open('/tmp', 'PHPSESSID'));
}
public function testClose()
{
$this->assertTrue($this->handler->close());
}
public function testWrite()
{
$this->memcached->method('set')->willReturn(true);
$this->assertTrue($this->handler->write('id', 'data'));
}
public function testDestroy()
{
$this->memcached->method('delete')->willReturn(true);
$this->assertTrue($this->handler->destroy('id'));
}
public function testGc()
{
$this->assertNotFalse($this->handler->gc(3600));
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function testCreate_sid()
{
$this->memcached->method('get')->willReturn(false);
$sid = $this->handler->create_sid();
$this->assertIsString($sid);
$this->assertMatchesRegularExpression('/^[a-f0-9]{64}$/', $sid);
}
public function testValidateId()
{
$this->memcached->method('get')->willReturn('somedata');
$this->assertTrue($this->handler->validateId('id'));
}
public function testValidateIdMissing()
{
$this->memcached->method('get')->willReturn(false);
$this->assertFalse($this->handler->validateId('nonexistent'));
}
public function testUpdateTimestamp()
{
$this->memcached->method('touch')->willReturn(true);
$this->assertTrue($this->handler->updateTimestamp('id', 'data'));
}
}