1 | <?php |
||||
2 | |||||
3 | declare(strict_types=1); |
||||
4 | |||||
5 | namespace Kodus\Cache\Test\Integration; |
||||
6 | |||||
7 | use Cache\IntegrationTests\SimpleCacheTest; |
||||
8 | use Codeception\Util\FileSystem; |
||||
9 | use Kodus\Cache\FileCache; |
||||
10 | use TypeError; |
||||
11 | |||||
12 | class FileCacheIntegrationTest extends SimpleCacheTest |
||||
13 | { |
||||
14 | const DEFAULT_EXPIRATION = 86400; |
||||
15 | const DIR_MODE = 0775; |
||||
16 | const FILE_MODE = 0664; |
||||
17 | |||||
18 | protected $skippedTests = [ |
||||
19 | 'testGetInvalidKeys' => 'New simple-cache v3 type hints break the test. FileCacheIntegrationTest contains updated versions.', |
||||
20 | 'testGetMultipleInvalidKeys' => 'New simple-cache v3 type hints break the test. FileCacheIntegrationTest contains updated versions.', |
||||
21 | 'testSetInvalidKeys' => 'New simple-cache v3 type hints break the test. FileCacheIntegrationTest contains updated versions.', |
||||
22 | 'testHasInvalidKeys' => 'New simple-cache v3 type hints break the test. FileCacheIntegrationTest contains updated versions.', |
||||
23 | 'testDeleteInvalidKeys' => 'New simple-cache v3 type hints break the test. FileCacheIntegrationTest contains updated versions.', |
||||
24 | ]; |
||||
25 | |||||
26 | public function createSimpleCache() |
||||
27 | { |
||||
28 | $path = dirname(__DIR__) . "/_output/cache"; |
||||
29 | |||||
30 | FileSystem::deleteDir($path); |
||||
31 | |||||
32 | $cache = new FileCache($path, self::DEFAULT_EXPIRATION, self::DIR_MODE, self::FILE_MODE); |
||||
33 | |||||
34 | assert(file_exists($path)); |
||||
35 | |||||
36 | assert(is_writable($path)); |
||||
37 | |||||
38 | return $cache; |
||||
39 | } |
||||
40 | |||||
41 | /** |
||||
42 | * @dataProvider invalidStringKeys |
||||
43 | */ |
||||
44 | public function testGetInvalidStringKeys($key) |
||||
45 | { |
||||
46 | $this->expectException('Psr\SimpleCache\InvalidArgumentException'); |
||||
47 | $this->cache->get($key); |
||||
48 | } |
||||
49 | |||||
50 | /** |
||||
51 | * @dataProvider invalidNonStringKeys |
||||
52 | */ |
||||
53 | public function testGetInvalidNonStringKeys($key) |
||||
54 | { |
||||
55 | $this->expectException(TypeError::class); |
||||
56 | $this->cache->get($key); |
||||
57 | } |
||||
58 | |||||
59 | /** |
||||
60 | * @dataProvider invalidStringKeys |
||||
61 | */ |
||||
62 | public function testGetMultipleInvalidStringKeys($key) |
||||
63 | { |
||||
64 | $this->expectException('Psr\SimpleCache\InvalidArgumentException'); |
||||
65 | $this->cache->getMultiple(['key1', $key, 'key2']); |
||||
66 | } |
||||
67 | |||||
68 | /** |
||||
69 | * @dataProvider invalidNonStringKeys |
||||
70 | */ |
||||
71 | public function testGetMultipleInvalidNonStringKeys($key) |
||||
72 | { |
||||
73 | $this->expectException(TypeError::class); |
||||
74 | $this->cache->getMultiple(['key1', $key, 'key2']); |
||||
75 | } |
||||
76 | |||||
77 | public function testGetMultipleNoIterable() |
||||
78 | { |
||||
79 | $this->expectException(TypeError::class); |
||||
80 | $this->cache->getMultiple('key'); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
81 | } |
||||
82 | |||||
83 | /** |
||||
84 | * @dataProvider invalidStringKeys |
||||
85 | */ |
||||
86 | public function testSetInvalidStringKeys($key) |
||||
87 | { |
||||
88 | $this->expectException('Psr\SimpleCache\InvalidArgumentException'); |
||||
89 | $this->cache->set($key, 'foobar'); |
||||
90 | } |
||||
91 | |||||
92 | /** |
||||
93 | * @dataProvider invalidNonStringKeys |
||||
94 | */ |
||||
95 | public function testSetInvalidNonStringKeys($key) |
||||
96 | { |
||||
97 | $this->expectException(TypeError::class); |
||||
98 | $this->cache->set($key, 'foobar'); |
||||
99 | } |
||||
100 | |||||
101 | public function testSetMultipleNoIterable() |
||||
102 | { |
||||
103 | $this->expectException(TypeError::class); |
||||
104 | $this->cache->setMultiple('key'); |
||||
0 ignored issues
–
show
'key' of type string is incompatible with the type iterable expected by parameter $values of Psr\SimpleCache\CacheInterface::setMultiple() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
105 | } |
||||
106 | |||||
107 | /** |
||||
108 | * @dataProvider invalidStringKeys |
||||
109 | */ |
||||
110 | public function testHasInvalidStringKeys($key) |
||||
111 | { |
||||
112 | $this->expectException('Psr\SimpleCache\InvalidArgumentException'); |
||||
113 | $this->cache->has($key); |
||||
114 | } |
||||
115 | /** |
||||
116 | * @dataProvider invalidNonStringKeys |
||||
117 | */ |
||||
118 | public function testHasInvalidNonStringKeys($key) |
||||
119 | { |
||||
120 | $this->expectException(TypeError::class); |
||||
121 | $this->cache->has($key); |
||||
122 | } |
||||
123 | |||||
124 | /** |
||||
125 | * @dataProvider invalidStringKeys |
||||
126 | */ |
||||
127 | public function testDeleteInvalidStringKeys($key) |
||||
128 | { |
||||
129 | $this->expectException('Psr\SimpleCache\InvalidArgumentException'); |
||||
130 | $this->cache->delete($key); |
||||
131 | } |
||||
132 | |||||
133 | /** |
||||
134 | * @dataProvider invalidNonStringKeys |
||||
135 | */ |
||||
136 | public function testDeleteInvalidNonStringKeys($key) |
||||
137 | { |
||||
138 | $this->expectException(TypeError::class); |
||||
139 | $this->cache->delete($key); |
||||
140 | } |
||||
141 | |||||
142 | |||||
143 | public function testDeleteMultipleNoIterable() |
||||
144 | { |
||||
145 | $this->expectException(TypeError::class); |
||||
146 | $this->cache->deleteMultiple('key'); |
||||
0 ignored issues
–
show
'key' of type string is incompatible with the type iterable expected by parameter $keys of Psr\SimpleCache\CacheInterface::deleteMultiple() .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
147 | } |
||||
148 | |||||
149 | /** |
||||
150 | * @dataProvider invalidTtl |
||||
151 | */ |
||||
152 | public function testSetInvalidTtl($ttl) |
||||
153 | { |
||||
154 | $this->expectException(TypeError::class); |
||||
155 | $this->cache->set('key', 'value', $ttl); |
||||
156 | } |
||||
157 | |||||
158 | /** |
||||
159 | * @dataProvider invalidTtl |
||||
160 | */ |
||||
161 | public function testSetMultipleInvalidTtl($ttl) |
||||
162 | { |
||||
163 | $this->expectException(TypeError::class); |
||||
164 | $this->cache->setMultiple(['key' => 'value'], $ttl); |
||||
165 | } |
||||
166 | |||||
167 | public static function invalidNonStringKeys() |
||||
168 | { |
||||
169 | return [ |
||||
170 | [true], |
||||
171 | [false], |
||||
172 | [null], |
||||
173 | [2.5], |
||||
174 | [new \stdClass()], |
||||
175 | [['array']], |
||||
176 | ]; |
||||
177 | } |
||||
178 | |||||
179 | public static function invalidStringKeys() |
||||
180 | { |
||||
181 | return [ |
||||
182 | [''], |
||||
183 | ['{str'], |
||||
184 | ['rand{'], |
||||
185 | ['rand{str'], |
||||
186 | ['rand}str'], |
||||
187 | ['rand(str'], |
||||
188 | ['rand)str'], |
||||
189 | ['rand/str'], |
||||
190 | ['rand\\str'], |
||||
191 | ['rand@str'], |
||||
192 | ['rand:str'], |
||||
193 | ]; |
||||
194 | } |
||||
195 | } |
||||
196 |