This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | declare(strict_types = 1); |
||
3 | |||
4 | namespace RoaveTest\DoctrineSimpleCache; |
||
5 | |||
6 | use Doctrine\Common\Cache\ArrayCache; |
||
7 | use PHPUnit\Framework\TestCase; |
||
8 | use Roave\DoctrineSimpleCache\Exception\CacheException; |
||
9 | use Roave\DoctrineSimpleCache\Exception\InvalidArgumentException; |
||
10 | use Roave\DoctrineSimpleCache\SimpleCacheAdapter; |
||
11 | use RoaveTestAsset\DoctrineSimpleCache\FullyImplementedCache; |
||
12 | use RoaveTestAsset\DoctrineSimpleCache\NotClearableCache; |
||
13 | use RoaveTestAsset\DoctrineSimpleCache\NotMultiOperationCache; |
||
14 | |||
15 | /** |
||
16 | * @covers \Roave\DoctrineSimpleCache\SimpleCacheAdapter |
||
17 | */ |
||
18 | final class SimpleCacheAdapterTest extends TestCase |
||
19 | { |
||
20 | public function invalidTTLs() : array |
||
21 | { |
||
22 | return [ |
||
23 | [''], |
||
24 | [true], |
||
25 | [false], |
||
26 | ['abc'], |
||
27 | [2.5], |
||
28 | [' 1'], // can be casted to a int |
||
29 | ['12foo'], // can be casted to a int |
||
30 | ['025'], // can be interpreted as hex |
||
31 | [new \stdClass()], |
||
32 | [['array']], |
||
33 | ]; |
||
34 | } |
||
35 | |||
36 | public function validKeys() |
||
37 | { |
||
38 | return [ |
||
39 | ['AbC19_.'], |
||
40 | ['1234567890123456789012345678901234567890123456789012345678901234'], |
||
41 | ]; |
||
42 | } |
||
43 | |||
44 | public function invalidKeys() |
||
45 | { |
||
46 | return [ |
||
47 | [''], |
||
48 | [true], |
||
49 | [false], |
||
50 | [null], |
||
51 | [2], |
||
52 | [2.5], |
||
53 | ['{str'], |
||
54 | ['rand{'], |
||
55 | ['rand{str'], |
||
56 | ['rand}str'], |
||
57 | ['rand(str'], |
||
58 | ['rand)str'], |
||
59 | ['rand/str'], |
||
60 | ['rand\\str'], |
||
61 | ['rand@str'], |
||
62 | ['rand:str'], |
||
63 | [new \stdClass()], |
||
64 | [['array']], |
||
65 | ]; |
||
66 | } |
||
67 | |||
68 | View Code Duplication | public function testConstructorThrowsExceptionWhenNotMultiOperationCacheIsUsed() |
|
0 ignored issues
–
show
|
|||
69 | { |
||
70 | /** @var NotMultiOperationCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
71 | $doctrineCache = $this->createMock(NotMultiOperationCache::class); |
||
72 | |||
73 | $this->expectException(CacheException::class); |
||
74 | $this->expectExceptionMessage('not support multiple operations'); |
||
75 | new SimpleCacheAdapter($doctrineCache); |
||
76 | } |
||
77 | |||
78 | View Code Duplication | public function testConstructorThrowsExceptionWhenNotClearableCacheIsUsed() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
79 | { |
||
80 | /** @var NotClearableCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
81 | $doctrineCache = $this->createMock(NotClearableCache::class); |
||
82 | |||
83 | $this->expectException(CacheException::class); |
||
84 | $this->expectExceptionMessage('not clearable'); |
||
85 | new SimpleCacheAdapter($doctrineCache); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
90 | */ |
||
91 | View Code Duplication | public function testGetProxiesToDoctrineFetch() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
92 | { |
||
93 | $key = uniqid('key', true); |
||
94 | $value = uniqid('value', true); |
||
95 | |||
96 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
97 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
98 | $doctrineCache->expects(self::once())->method('fetch')->with($key)->willReturn($value); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
99 | |||
100 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
101 | self::assertSame($value, $psrCache->get($key)); |
||
102 | } |
||
103 | |||
104 | /** |
||
105 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
106 | */ |
||
107 | public function testGetWithNotExistingKey() |
||
108 | { |
||
109 | $key = uniqid('key', true); |
||
110 | $value = uniqid('value', true); |
||
111 | |||
112 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
113 | $psrCache->set($key, $value); |
||
114 | |||
115 | $default = uniqid('default', true); |
||
116 | self::assertSame($value, $psrCache->get($key, $default)); |
||
117 | |||
118 | $anotherKey = uniqid('key', true); |
||
119 | self::assertSame($default, $psrCache->get($anotherKey, $default)); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
124 | */ |
||
125 | View Code Duplication | public function testGetWithFalseValueStoredInCache() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
126 | { |
||
127 | $key = uniqid('key', true); |
||
128 | |||
129 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
130 | $psrCache->set($key, false); |
||
131 | |||
132 | self::assertFalse($psrCache->get($key, uniqid('default', true))); |
||
133 | } |
||
134 | |||
135 | /** |
||
136 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
137 | * @throws \Exception |
||
138 | */ |
||
139 | public function testSetProxiesToDoctrineSave() |
||
140 | { |
||
141 | $key = uniqid('key', true); |
||
142 | $value = uniqid('value', true); |
||
143 | $ttl = random_int(1000, 9999); |
||
144 | |||
145 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
146 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
147 | $doctrineCache->expects(self::once())->method('save')->with($key, $value, $ttl)->willReturn(true); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
148 | |||
149 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
150 | self::assertTrue($psrCache->set($key, $value, $ttl)); |
||
151 | } |
||
152 | |||
153 | /** |
||
154 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
155 | */ |
||
156 | public function testSetWithDateIntervalTTL() |
||
157 | { |
||
158 | $key = uniqid('key', true); |
||
159 | $value = uniqid('value', true); |
||
160 | $ttl_date = \DateInterval::createFromDateString('1 day'); |
||
161 | |||
162 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
163 | |||
164 | // This does not test if ttl is correctly set to 86400 sec. |
||
165 | self::assertTrue($psrCache->set($key, $value, $ttl_date)); |
||
166 | self::assertSame($psrCache->get($key), $value); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
171 | * @throws \Exception |
||
172 | */ |
||
173 | public function testSetWithNonPositiveTTL() |
||
174 | { |
||
175 | $key = uniqid('key', true); |
||
176 | $value = uniqid('value', true); |
||
177 | $ttl = random_int(1000, 9999); |
||
178 | |||
179 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
180 | |||
181 | $psrCache->set($key, $value, $ttl); |
||
182 | self::assertSame($psrCache->get($key), $value); |
||
183 | |||
184 | $psrCache->set($key, $value, -1); |
||
185 | self::assertNull($psrCache->get($key)); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * @param mixed $ttl |
||
190 | * @dataProvider invalidTTLs |
||
191 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
192 | */ |
||
193 | View Code Duplication | public function testSetWithInvalidTTL($ttl) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
194 | { |
||
195 | $key = uniqid('key', true); |
||
196 | $value = uniqid('value', true); |
||
197 | |||
198 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
199 | |||
200 | $this->expectException(InvalidArgumentException::class); |
||
201 | $psrCache->set($key, $value, $ttl); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
206 | */ |
||
207 | View Code Duplication | public function testDeleteProxiesToDoctrineDelete() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
208 | { |
||
209 | $key = uniqid('key', true); |
||
210 | |||
211 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
212 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
213 | $doctrineCache->expects(self::once())->method('delete')->with($key)->willReturn(true); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
214 | |||
215 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
216 | self::assertTrue($psrCache->delete($key)); |
||
217 | } |
||
218 | |||
219 | public function testClearProxiesToDeleteAll() |
||
220 | { |
||
221 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
222 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
223 | $doctrineCache->expects(self::once())->method('deleteAll')->with()->willReturn(true); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
224 | |||
225 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
226 | self::assertTrue($psrCache->clear()); |
||
227 | } |
||
228 | |||
229 | public function testGetMultipleProxiesToFetchMultiple() |
||
230 | { |
||
231 | $values = [ |
||
232 | uniqid('key1', true) => uniqid('value1', true), |
||
233 | uniqid('key2', true) => uniqid('value2', true), |
||
234 | ]; |
||
235 | $keys = array_keys($values); |
||
236 | |||
237 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
238 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
239 | $doctrineCache->expects(self::once())->method('fetchMultiple')->with($keys)->willReturn($values); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
240 | |||
241 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
242 | self::assertSame($values, $psrCache->getMultiple($keys)); |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * @throws \Exception |
||
247 | */ |
||
248 | public function testGetMultipleWithPartialKeys() |
||
249 | { |
||
250 | $values = [ |
||
251 | uniqid('key1', true) => uniqid('value1', true), |
||
252 | uniqid('key2', true) => uniqid('value2', true), |
||
253 | ]; |
||
254 | $keys = array_keys($values); |
||
255 | |||
256 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
257 | $psrCache->setMultiple($values); |
||
258 | |||
259 | $default = uniqid('default', true); |
||
260 | $invalid_key = uniqid('key3', true); |
||
261 | $keys[] = $invalid_key; |
||
262 | $values[$invalid_key] = $default; |
||
263 | |||
264 | self::assertSame($values, $psrCache->getMultiple($keys, $default)); |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * @param mixed $key |
||
269 | * @dataProvider invalidKeys |
||
270 | */ |
||
271 | public function testGetMultipleThrowsExceptionWithInvalidKeys($key) |
||
272 | { |
||
273 | $this->expectException(InvalidArgumentException::class); |
||
274 | |||
275 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
276 | $psrCache->getMultiple([$key]); |
||
277 | } |
||
278 | |||
279 | /** |
||
280 | * @param mixed $key |
||
281 | * @dataProvider validKeys |
||
282 | */ |
||
283 | View Code Duplication | public function testGetMultipleAcceptsTraversable($key) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
284 | { |
||
285 | $values = [ |
||
286 | $key => uniqid('value', true), |
||
287 | ]; |
||
288 | |||
289 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
290 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
291 | $doctrineCache->expects(self::once())->method('fetchMultiple')->with(array_keys($values))->willReturn($values); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
292 | |||
293 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
294 | $psrCache->getMultiple(new \ArrayObject(array_keys($values))); |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * @throws \Exception |
||
299 | */ |
||
300 | public function testGetMultipleAcceptsGenerator() |
||
301 | { |
||
302 | $values = [ |
||
303 | uniqid('key0', true) => uniqid('value0', true), |
||
304 | uniqid('key1', true) => uniqid('value1', true), |
||
305 | ]; |
||
306 | |||
307 | $generator = function () use ($values) { |
||
308 | /** @noinspection ForeachOnArrayComponentsInspection */ |
||
309 | foreach (array_keys($values) as $k) { |
||
310 | yield $k; |
||
311 | } |
||
312 | }; |
||
313 | |||
314 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
315 | $psrCache->setMultiple($values); |
||
316 | |||
317 | self::assertSame($values, $psrCache->getMultiple($generator())); |
||
318 | } |
||
319 | |||
320 | View Code Duplication | public function testGetMultipleThrowsExceptionWhenNotArrayOrTraversable() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
321 | { |
||
322 | $this->expectException(InvalidArgumentException::class); |
||
323 | |||
324 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
325 | $psrCache->getMultiple(uniqid('string', true)); |
||
0 ignored issues
–
show
uniqid('string', true) is of type string , but the function expects a array|object<Traversable> .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
326 | } |
||
327 | |||
328 | /** |
||
329 | * @throws \Exception |
||
330 | */ |
||
331 | public function testSetMultipleProxiesToSaveMultiple() |
||
332 | { |
||
333 | $values = [ |
||
334 | uniqid('key1', true) => uniqid('value1', true), |
||
335 | uniqid('key2', true) => uniqid('value2', true), |
||
336 | ]; |
||
337 | |||
338 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
339 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
340 | $doctrineCache->expects(self::once())->method('saveMultiple')->with($values)->willReturn(true); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
341 | |||
342 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
343 | self::assertTrue($psrCache->setMultiple($values)); |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * @throws \Exception |
||
348 | */ |
||
349 | public function testSetMultipleWithDateIntervalTTL() |
||
350 | { |
||
351 | $values = [ |
||
352 | uniqid('key1', true) => uniqid('value1', true), |
||
353 | uniqid('key2', true) => uniqid('value2', true), |
||
354 | ]; |
||
355 | $keys = array_keys($values); |
||
356 | $ttl_date = \DateInterval::createFromDateString('1 day'); |
||
357 | |||
358 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
359 | |||
360 | // This does not test if ttl is correctly set to 86400 sec. |
||
361 | self::assertTrue($psrCache->setMultiple($values, $ttl_date)); |
||
362 | self::assertSame($values, $psrCache->getMultiple($keys)); |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
367 | */ |
||
368 | public function testSetMultipleWithNonPositiveTTL() |
||
369 | { |
||
370 | $values = [ |
||
371 | uniqid('key1', true) => uniqid('value1', true), |
||
372 | uniqid('key2', true) => uniqid('value2', true), |
||
373 | ]; |
||
374 | $keys = array_keys($values); |
||
375 | |||
376 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
377 | $psrCache->setMultiple($values); |
||
378 | |||
379 | $volatile = [$keys[0] => uniqid('value3', true)]; |
||
380 | $psrCache->setMultiple($volatile, -1); |
||
381 | |||
382 | self::assertNull($psrCache->get($keys[0])); |
||
383 | self::assertNotNull($psrCache->get($keys[1])); |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * @param mixed $ttl |
||
388 | * @dataProvider invalidTTLs |
||
389 | * @throws \Exception |
||
390 | */ |
||
391 | public function testSetMultipleWithInvalidTTL($ttl) |
||
392 | { |
||
393 | $values = [ |
||
394 | uniqid('key1', true) => uniqid('value1', true), |
||
395 | uniqid('key2', true) => uniqid('value2', true), |
||
396 | ]; |
||
397 | |||
398 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
399 | |||
400 | $this->expectException(InvalidArgumentException::class); |
||
401 | $psrCache->setMultiple($values, $ttl); |
||
402 | } |
||
403 | |||
404 | View Code Duplication | public function testSetMultipleThrowsExceptionWhenNotArrayOrTraversable() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
405 | { |
||
406 | $this->expectException(InvalidArgumentException::class); |
||
407 | |||
408 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
409 | $psrCache->setMultiple(uniqid('string', true)); |
||
0 ignored issues
–
show
uniqid('string', true) is of type string , but the function expects a array|object<Traversable> .
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: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
410 | } |
||
411 | |||
412 | /** |
||
413 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
414 | * @throws \Exception |
||
415 | */ |
||
416 | public function testSetMultipleAcceptsGenerator() |
||
417 | { |
||
418 | $key0 = uniqid('key0', true); |
||
419 | $key1 = uniqid('key1', true); |
||
420 | $values = [ |
||
421 | $key0 => uniqid('value0', true), |
||
422 | $key1 => uniqid('value1', true), |
||
423 | ]; |
||
424 | |||
425 | $generator = function () use ($values) { |
||
426 | foreach ($values as $k => $v) { |
||
427 | yield $k => $v; |
||
428 | } |
||
429 | }; |
||
430 | |||
431 | $psrCache = new SimpleCacheAdapter(new ArrayCache()); |
||
432 | $psrCache->setMultiple($generator()); |
||
433 | |||
434 | self::assertSame($values[$key0], $psrCache->get($key0)); |
||
435 | self::assertSame($values[$key1], $psrCache->get($key1)); |
||
436 | } |
||
437 | |||
438 | View Code Duplication | public function testDeleteMultipleReturnsTrueWhenAllDeletesSucceed() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
439 | { |
||
440 | $keys = [ |
||
441 | uniqid('key1', true), |
||
442 | uniqid('key2', true), |
||
443 | ]; |
||
444 | |||
445 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
446 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
447 | $doctrineCache->expects(self::once())->method('deleteMultiple')->with($keys)->willReturn(true); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
448 | |||
449 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
450 | self::assertTrue($psrCache->deleteMultiple($keys)); |
||
451 | } |
||
452 | |||
453 | View Code Duplication | public function testDeleteMultipleReturnsFalseWhenOneDeleteFails() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
454 | { |
||
455 | $keys = [ |
||
456 | uniqid('key1', true), |
||
457 | uniqid('key2', true), |
||
458 | ]; |
||
459 | |||
460 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
461 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
462 | $doctrineCache->expects(self::once())->method('deleteMultiple')->with($keys)->willReturn(false); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
463 | |||
464 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
465 | self::assertFalse($psrCache->deleteMultiple($keys)); |
||
466 | } |
||
467 | |||
468 | /** |
||
469 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
470 | */ |
||
471 | View Code Duplication | public function testHasProxiesToDoctrineContains() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. ![]() |
|||
472 | { |
||
473 | $key = uniqid('key', true); |
||
474 | |||
475 | /** @var FullyImplementedCache|\PHPUnit_Framework_MockObject_MockObject $doctrineCache */ |
||
476 | $doctrineCache = $this->createMock(FullyImplementedCache::class); |
||
477 | $doctrineCache->expects(self::once())->method('contains')->with($key)->willReturn(true); |
||
0 ignored issues
–
show
The method
expects() does not seem to exist on object<RoaveTestAsset\Do...\FullyImplementedCache> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
478 | |||
479 | $psrCache = new SimpleCacheAdapter($doctrineCache); |
||
480 | self::assertTrue($psrCache->has($key)); |
||
481 | } |
||
482 | } |
||
483 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.