|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Tests\Cache\Storage; |
|
4
|
|
|
|
|
5
|
|
|
use Ds\Cache\Storage\FileStorage; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class FileStorageTest |
|
9
|
|
|
* |
|
10
|
|
|
* @package Tests\Cache\Storage |
|
11
|
|
|
*/ |
|
12
|
|
|
class FileStorageTest extends \PHPUnit_Framework_TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var FileStorage |
|
17
|
|
|
*/ |
|
18
|
|
|
public $cacheStorage; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @var |
|
22
|
|
|
*/ |
|
23
|
|
|
public $testDir; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* |
|
27
|
|
|
*/ |
|
28
|
|
|
public function setUp() |
|
29
|
|
|
{ |
|
30
|
|
|
$this->testDir = __DIR__ . '/cacheTest'; |
|
31
|
|
|
$this->cacheStorage = new FileStorage( $this->testDir, new \DateInterval('P1M')); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testUnwritableDirectory() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->expectException('\Exception'); |
|
40
|
|
|
$this->cacheStorage = new FileStorage(false, new \DateInterval('P1M')); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* |
|
45
|
|
|
*/ |
|
46
|
|
|
public function testSet(){ |
|
47
|
|
|
$actual = $this->cacheStorage->set('key','value',60*60); |
|
48
|
|
|
$this->assertEquals(true, $actual); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* |
|
53
|
|
|
*/ |
|
54
|
|
|
public function testHasNoValue(){ |
|
55
|
|
|
$this->assertEquals($this->cacheStorage->has('someRandomKey'), false); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* |
|
60
|
|
|
*/ |
|
61
|
|
|
public function testHas(){ |
|
62
|
|
|
$this->cacheStorage->set('foo','bar'); |
|
63
|
|
|
$this->assertEquals($this->cacheStorage->has('foo'), true); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* |
|
68
|
|
|
*/ |
|
69
|
|
|
public function testHasExpired(){ |
|
70
|
|
|
$this->cacheStorage->set('expired','bar', -1200); |
|
71
|
|
|
$this->assertEquals($this->cacheStorage->has('expired'), false); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* |
|
76
|
|
|
*/ |
|
77
|
|
|
public function testClear(){ |
|
78
|
|
|
$this->assertEquals($this->cacheStorage->clear(), true); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* |
|
83
|
|
|
*/ |
|
84
|
|
|
public function testGet(){ |
|
85
|
|
|
$expected = 'bat'; |
|
86
|
|
|
$this->cacheStorage->set('baz',$expected); |
|
87
|
|
|
$actual = $this->cacheStorage->get('baz'); |
|
88
|
|
|
$this->assertEquals($expected, $actual); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Clean up any cache files left on system. |
|
93
|
|
|
*/ |
|
94
|
|
|
public function tearDown() |
|
95
|
|
|
{ |
|
96
|
|
|
$dir = $this->testDir; |
|
97
|
|
|
|
|
98
|
|
|
if (is_dir( $dir)){ |
|
99
|
|
|
array_map('unlink', glob("$dir/*.*")); |
|
100
|
|
|
} |
|
101
|
|
|
\rmdir($dir); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
} |
|
105
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: