Repository navigation
Expand file tree
/
Copy pathFileHandlerTest.php
More file actions
106 lines (85 loc) · 2.85 KB
/
Copy pathFileHandlerTest.php
File metadata and controls
106 lines (85 loc) · 2.85 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
<?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 $sessionName;
/** @var string */
protected $sessionFile;
public function setUp()
{
$this->vfs = VfsStream::setup();
$this->savePath = $this->vfs->url();
$this->sessionName = 'george';
$this->sessionFile = $this->savePath . '/' . $this->sessionName . '.sess';
}
public function testConstructor()
{
$this->assertClassHasAttribute('savePath', FileHandler::class);
$this->assertClassHasAttribute('fs', FileHandler::class);
$fsh = new FileHandler($this->savePath);
$this->assertObjectHasAttribute('savePath', $fsh);
$this->assertObjectHasAttribute('fs', $fsh);
$this->assertAttributeEquals($this->savePath, 'savePath', $fsh);
}
public function testOpen()
{
$fsh = new FileHandler($this->savePath);
$result = $fsh->open($this->savePath, $this->sessionName);
$this->assertTrue($result);
}
public function testClose()
{
$fsh = new FileHandler($this->savePath);
$result = $fsh->close();
$this->assertTrue($result);
}
/**
* @covers \Bolt\Session\Handler\FileHandler::write
* @covers \Bolt\Session\Handler\FileHandler::read
*/
public function testWriteRead()
{
$fsh = new FileHandler($this->savePath);
$fsh->open($this->savePath, $this->sessionName);
$result = $fsh->write($this->sessionName, 'kittens');
$this->assertTrue($result);
$result = $fsh->read($this->sessionName);
$this->assertSame('kittens', $result);
$this->assertStringEqualsFile($this->sessionFile, 'kittens');
}
public function testDestroy()
{
$fsh = new FileHandler($this->savePath);
$fsh->open($this->savePath, $this->sessionName);
$fsh->write($this->sessionName, 'kittens');
$this->assertFileExists($this->sessionFile);
$result = $fsh->destroy($this->sessionName);
$this->assertTrue($result);
$this->assertFileNotExists($this->sessionName);
}
public function testGc()
{
$fsh = new FileHandler($this->savePath);
$fsh->open($this->savePath, $this->sessionName);
$fsh->write($this->sessionName, 'kittens');
$this->assertFileExists($this->sessionFile);
sleep(1);
$result = $fsh->gc(1);
$this->assertTrue($result);
$this->assertFileNotExists($this->sessionName);
}
}