-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSymfonyCacheSessionHandlerTest.php
More file actions
108 lines (85 loc) · 3.18 KB
/
Copy pathSymfonyCacheSessionHandlerTest.php
File metadata and controls
108 lines (85 loc) · 3.18 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
namespace Detain\SessionSamuraiTest;
use PHPUnit\Framework\TestCase;
use Psr\Cache\CacheItemInterface;
use Psr\Cache\CacheItemPoolInterface;
use Detain\SessionSamurai\SymfonyCacheSessionHandler;
class SymfonyCacheSessionHandlerTest extends TestCase
{
private CacheItemPoolInterface $cache;
private SymfonyCacheSessionHandler $handler;
public function setUp(): void
{
$this->cache = $this->createMock(CacheItemPoolInterface::class);
$this->handler = new SymfonyCacheSessionHandler($this->cache);
}
public function testOpen()
{
$this->assertTrue($this->handler->open('', ''));
}
public function testClose()
{
$this->assertTrue($this->handler->close());
}
public function testRead()
{
$sessionId = 'foo';
$sessionData = 'bar';
$cacheItem = $this->createMock(CacheItemInterface::class);
$cacheItem->method('isHit')->willReturn(true);
$cacheItem->method('get')->willReturn($sessionData);
$this->cache->method('getItem')->willReturn($cacheItem);
$this->assertEquals($sessionData, $this->handler->read($sessionId));
}
public function testReadNonExistent()
{
$sessionId = 'foo';
$cacheItem = $this->createMock(CacheItemInterface::class);
$cacheItem->method('isHit')->willReturn(false);
$this->cache->method('getItem')->willReturn($cacheItem);
$this->assertEquals('', $this->handler->read($sessionId));
}
public function testWrite()
{
$sessionId = 'foo';
$sessionData = 'bar';
$cacheItem = $this->createMock(CacheItemInterface::class);
$cacheItem->method('set')->willReturn($cacheItem);
$cacheItem->method('expiresAfter')->willReturn($cacheItem);
$this->cache->method('getItem')->willReturn($cacheItem);
$this->cache->method('save')->willReturn(true);
$this->assertTrue($this->handler->write($sessionId, $sessionData));
}
public function testDestroy()
{
$this->cache->method('deleteItem')->willReturn(true);
$this->assertTrue($this->handler->destroy('foo'));
}
public function testGc()
{
$this->assertNotFalse($this->handler->gc(123));
}
public function testCreateSid()
{
$sid = $this->handler->create_sid();
$this->assertMatchesRegularExpression('/^[a-f0-9]{64}$/', $sid);
}
public function testUpdateTimestamp()
{
$sessionId = 'foo';
$sessionData = 'bar';
$cacheItem = $this->createMock(CacheItemInterface::class);
$cacheItem->method('set')->willReturn($cacheItem);
$cacheItem->method('expiresAfter')->willReturn($cacheItem);
$this->cache->method('getItem')->willReturn($cacheItem);
$this->cache->method('save')->willReturn(true);
$this->assertTrue($this->handler->updateTimestamp($sessionId, $sessionData));
}
public function testValidateId()
{
$cacheItem = $this->createMock(CacheItemInterface::class);
$cacheItem->method('isHit')->willReturn(true);
$this->cache->method('getItem')->willReturn($cacheItem);
$this->assertTrue($this->handler->validateId('foo'));
}
}