-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedisSessionHandlerTest.php
More file actions
79 lines (66 loc) · 2.25 KB
/
Copy pathRedisSessionHandlerTest.php
File metadata and controls
79 lines (66 loc) · 2.25 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
<?php
namespace Detain\SessionSamuraiTest;
use PHPUnit\Framework\TestCase;
use Detain\SessionSamurai\RedisSessionHandler;
class RedisSessionHandlerTest extends TestCase
{
protected static $redis;
protected static $sessionId;
public static function setUpBeforeClass(): void
{
self::$redis = new \Redis();
self::$redis->connect('67.217.60.234', 6379);
self::$sessionId = bin2hex(random_bytes(32));
}
public function testOpen()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertTrue($handler->open('', ''));
}
public function testClose()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertTrue($handler->close());
}
public function testRead()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertEquals('', $handler->read(self::$sessionId));
}
public function testWrite()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertTrue($handler->write(self::$sessionId, 'test data'));
$this->assertEquals('test data', $handler->read(self::$sessionId));
}
public function testGc()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertEquals(0, $handler->gc(0));
}
public function testCreateSid()
{
$handler = new RedisSessionHandler(self::$redis);
$sid = $handler->create_sid();
$this->assertIsString($sid);
$this->assertNotEquals('', $sid);
}
public function testValidateId()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertTrue($handler->validateId(self::$sessionId));
$this->assertFalse($handler->validateId('invalid-session-id'));
}
public function testUpdateTimestamp()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertTrue($handler->write(self::$sessionId, 'test data'));
$this->assertTrue($handler->updateTimestamp(self::$sessionId, 'test data'));
}
public function testDestroy()
{
$handler = new RedisSessionHandler(self::$redis);
$this->assertTrue($handler->destroy(self::$sessionId));
$this->assertEquals('', $handler->read(self::$sessionId));
}
}