Repository navigation
Expand file tree
/
Copy pathFileHandlerTest.php
More file actions
111 lines (87 loc) · 2.73 KB
/
Copy pathFileHandlerTest.php
File metadata and controls
111 lines (87 loc) · 2.73 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
109
110
111
<?php
namespace Bolt\Session\Tests\Handler;
use Bolt\Session\Handler\FileHandler;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
use PHPUnit\Framework\TestCase;
/**
* Class to test src/Handler/FileHandler.
*
* @author Gawain Lynch <gawain.lynch@gmail.com>
*/
class FileHandlerTest extends TestCase
{
/** @var vfsStreamDirectory */
protected $vfs;
/** @var string */
protected $savePath;
/** @var string */
protected $sessionId;
/** @var string */
protected $sessionFile;
public function setUp()
{
$this->vfs = VfsStream::setup();
$this->savePath = $this->vfs->url();
$this->sessionId = 'george';
$this->sessionFile = $this->savePath . '/' . $this->sessionId . '.sess';
}
public function testOpen()
{
$fsh = new FileHandler($this->savePath);
$result = $fsh->open(null, 'PHPSESSID');
$this->assertTrue($result);
}
public function testClose()
{
$fsh = new FileHandler($this->savePath);
$result = $fsh->close();
$this->assertTrue($result);
}
public function testRead()
{
file_put_contents($this->sessionFile, 'kittens');
$fsh = new FileHandler($this->savePath);
$result = $fsh->read($this->sessionId);
$this->assertSame('kittens', $result);
}
public function testReadNew()
{
$fsh = new FileHandler($this->savePath);
$result = $fsh->read('new');
$this->assertSame('', $result);
}
public function testReadUnreadable()
{
file_put_contents($this->savePath . '/unreadable.sess', '');
chmod($this->savePath . '/unreadable.sess', 0);
$fsh = new FileHandler($this->savePath);
$result = $fsh->read('unreadable');
$this->assertSame('', $result);
}
public function testWrite()
{
$fsh = new FileHandler($this->savePath);
$result = $fsh->write($this->sessionId, 'kittens');
$this->assertTrue($result);
$this->assertFileExists($this->sessionFile);
$this->assertStringEqualsFile($this->sessionFile, 'kittens');
}
public function testDestroy()
{
file_put_contents($this->sessionFile, 'kittens');
$fsh = new FileHandler($this->savePath);
$result = $fsh->destroy($this->sessionId);
$this->assertTrue($result);
$this->assertFileNotExists($this->sessionFile);
}
public function testGc()
{
file_put_contents($this->sessionFile, 'kittens');
touch($this->sessionFile, time() - 5);
$fsh = new FileHandler($this->savePath);
$result = $fsh->gc(1);
$this->assertTrue($result);
$this->assertFileNotExists($this->sessionFile);
}
}