-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlySystemSessionHandlerTest.php
More file actions
82 lines (67 loc) · 2.4 KB
/
Copy pathFlySystemSessionHandlerTest.php
File metadata and controls
82 lines (67 loc) · 2.4 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
<?php
namespace Detain\SessionSamuraiTest;
use PHPUnit\Framework\TestCase;
use Detain\SessionSamurai\FlySystemSessionHandler;
use League\Flysystem\FilesystemOperator;
class FlySystemSessionHandlerTest extends TestCase
{
private FilesystemOperator $filesystem;
private FlySystemSessionHandler $handler;
public function setUp(): void
{
$this->filesystem = $this->createMock(FilesystemOperator::class);
$this->handler = new FlySystemSessionHandler($this->filesystem, '/sessions');
}
public function testOpen()
{
$this->assertTrue($this->handler->open('/path', 'PHPSESSID'));
}
public function testClose()
{
$this->assertTrue($this->handler->close());
}
public function testReadNonExistent()
{
$this->filesystem->method('read')->willThrowException(new \League\Flysystem\UnableToReadFile('/sessions/abc123'));
$this->assertSame('', $this->handler->read('abc123'));
}
public function testRead()
{
$this->filesystem->method('read')->willReturn('sessiondata');
$this->assertSame('sessiondata', $this->handler->read('abc123'));
}
public function testWrite()
{
$this->assertTrue($this->handler->write('abc123', 'data'));
}
public function testDestroyExisting()
{
$this->assertTrue($this->handler->destroy('abc123'));
}
public function testDestroyNonExistent()
{
$this->filesystem->method('delete')->willThrowException(new \League\Flysystem\UnableToDeleteFile('/sessions/abc123'));
$this->assertTrue($this->handler->destroy('abc123'));
}
public function testGc()
{
$this->filesystem->method('listContents')->willReturn(new \League\Flysystem\DirectoryListing([]));
$this->assertNotFalse($this->handler->gc(100));
}
// 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()
{
$this->filesystem->method('fileExists')->willReturn(true);
$this->assertTrue($this->handler->validateId('abc123'));
}
public function testUpdateTimestamp()
{
$this->filesystem->method('read')->willReturn('data');
$this->assertTrue($this->handler->updateTimestamp('abc123', 'data'));
}
}