-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPhpFastCacheSessionHandlerTest.php
More file actions
94 lines (80 loc) · 2.98 KB
/
Copy pathPhpFastCacheSessionHandlerTest.php
File metadata and controls
94 lines (80 loc) · 2.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Detain\SessionSamuraiTest;
use PHPUnit\Framework\TestCase;
use Detain\SessionSamurai\PhpFastCacheSessionHandler;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\CacheItemInterface;
class PhpFastCacheSessionHandlerTest extends TestCase
{
private PhpFastCacheSessionHandler $handler;
private CacheItemPoolInterface $cache;
private string $sessionId;
public function setUp(): void
{
$this->cache = $this->createMock(CacheItemPoolInterface::class);
$this->handler = new PhpFastCacheSessionHandler($this->cache);
$this->sessionId = $this->handler->create_sid();
}
public function testOpen()
{
$this->assertTrue($this->handler->open('', ''));
}
public function testClose()
{
$this->assertTrue($this->handler->close());
}
public function testReadMiss()
{
$item = $this->createMock(CacheItemInterface::class);
$item->method('isHit')->willReturn(false);
$this->cache->method('getItem')->willReturn($item);
$this->assertSame('', $this->handler->read($this->sessionId));
}
public function testReadHit()
{
$item = $this->createMock(CacheItemInterface::class);
$item->method('isHit')->willReturn(true);
$item->method('get')->willReturn('foo');
$this->cache->method('getItem')->willReturn($item);
$this->assertSame('foo', $this->handler->read($this->sessionId));
}
public function testWrite()
{
$item = $this->createMock(CacheItemInterface::class);
$item->method('set')->willReturn($item);
$item->method('expiresAfter')->willReturn($item);
$this->cache->method('getItem')->willReturn($item);
$this->cache->method('save')->willReturn(true);
$this->assertTrue($this->handler->write($this->sessionId, 'foo'));
}
public function testDestroy()
{
$this->cache->method('deleteItem')->willReturn(true);
$this->assertTrue($this->handler->destroy($this->sessionId));
}
public function testGc()
{
$this->assertNotFalse($this->handler->gc(0));
}
// phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps
public function testCreate_sid()
{
$sid = $this->handler->create_sid();
$this->assertMatchesRegularExpression('/^[a-f0-9]{64}$/', $sid);
}
public function testValidateId()
{
$item = $this->createMock(CacheItemInterface::class);
$item->method('isHit')->willReturn(true);
$this->cache->method('getItem')->willReturn($item);
$this->assertTrue($this->handler->validateId($this->sessionId));
}
public function testUpdateTimestamp()
{
$item = $this->createMock(CacheItemInterface::class);
$item->method('expiresAfter')->willReturn($item);
$this->cache->method('getItem')->willReturn($item);
$this->cache->method('save')->willReturn(true);
$this->assertTrue($this->handler->updateTimestamp($this->sessionId, 'foo'));
}
}