-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFilesHandlerTest.php
More file actions
91 lines (82 loc) · 2.39 KB
/
Copy pathFilesHandlerTest.php
File metadata and controls
91 lines (82 loc) · 2.39 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
<?php
/*
* This file is part of Aplus Framework Session Library.
*
* (c) Natan Felles <natanfelles@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\Session\SaveHandlers;
use Framework\Session\SaveHandlers\FilesHandler;
/**
* Class FilesHandlerTest.
*
* @runTestsInSeparateProcesses
*/
class FilesHandlerTest extends AbstractHandler
{
protected string $handlerClass = FilesHandler::class;
public function setUp() : void
{
$directory = \getenv('FILES_DIR');
if ($directory && !\is_dir($directory)) {
\mkdir($directory, 0700, true);
}
$this->replaceConfig([
'directory' => $directory,
]);
parent::setUp();
}
public function testNoDirectory() : void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Session config has not a directory');
new FilesHandler();
}
public function testInvalidDirectory() : void
{
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Session config directory does not exist: foo');
new FilesHandler([
'directory' => 'foo',
]);
}
public function testPrefix() : void
{
$config = [
'prefix' => 'foo',
'directory' => \getenv('FILES_DIR'),
];
$handler = new class($config) extends FilesHandler {
public function getFilename(string $id) : string
{
return parent::getFilename($id);
}
};
self::assertSame(
\getenv('FILES_DIR') . '/foo/ab/abc123',
$handler->getFilename('abc123')
);
}
public function testFailToWrite() : void
{
$handler = new class($this->config) extends FilesHandler {
public $stream;
};
$handler->stream = null;
self::assertFalse($handler->write('foo', 'bar'));
}
public function testUnlockWithoutStream() : void
{
$handler = new class($this->config) extends FilesHandler {
public $stream;
public function unlock() : bool
{
return parent::unlock();
}
};
$handler->stream = null;
self::assertTrue($handler->unlock());
}
}