These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace DoctrineModuleTest\Cache; |
||
6 | |||
7 | use ArrayObject; |
||
8 | use Doctrine\Common\Cache\Cache; |
||
9 | use DoctrineModule\Cache\LaminasStorageCache; |
||
10 | use Laminas\Cache\Storage\Adapter\Memory; |
||
11 | use PHPUnit\Framework\TestCase; |
||
12 | |||
13 | /** |
||
14 | * Tests for the cache bridge |
||
15 | * |
||
16 | * @link http://www.doctrine-project.org/ |
||
17 | */ |
||
18 | class LaminasStorageCacheTest extends TestCase |
||
19 | { |
||
20 | protected function getCacheDriver() : LaminasStorageCache |
||
21 | { |
||
22 | return new LaminasStorageCache(new Memory()); |
||
23 | } |
||
24 | |||
25 | public function testBasics() : void |
||
26 | { |
||
27 | $cache = $this->getCacheDriver(); |
||
28 | |||
29 | // Test save |
||
30 | $cache->save('test_key', 'testing this out'); |
||
31 | |||
32 | // Test contains to test that save() worked |
||
33 | $this->assertTrue($cache->contains('test_key')); |
||
34 | |||
35 | // Test fetch |
||
36 | $this->assertEquals('testing this out', $cache->fetch('test_key')); |
||
37 | |||
38 | // Test delete |
||
39 | $cache->save('test_key2', 'test2'); |
||
40 | $cache->delete('test_key2'); |
||
41 | $this->assertFalse($cache->contains('test_key2')); |
||
0 ignored issues
–
show
|
|||
42 | |||
43 | // Fetch/save test with objects (Is cache driver serializes/unserializes objects correctly ?) |
||
44 | $cache->save('test_object_key', new ArrayObject()); |
||
45 | $this->assertInstanceOf('ArrayObject', $cache->fetch('test_object_key')); |
||
46 | } |
||
47 | |||
48 | public function testDeleteAll() : void |
||
49 | { |
||
50 | $cache = $this->getCacheDriver(); |
||
51 | $cache->save('test_key1', '1'); |
||
52 | $cache->save('test_key2', '2'); |
||
53 | $cache->deleteAll(); |
||
54 | |||
55 | $this->assertFalse($cache->contains('test_key1')); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<DoctrineModuleTes...aminasStorageCacheTest> .
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.
Loading history...
|
|||
56 | $this->assertFalse($cache->contains('test_key2')); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<DoctrineModuleTes...aminasStorageCacheTest> .
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.
Loading history...
|
|||
57 | } |
||
58 | |||
59 | public function testFlushAll() : void |
||
60 | { |
||
61 | $cache = $this->getCacheDriver(); |
||
62 | $cache->save('test_key1', '1'); |
||
63 | $cache->save('test_key2', '2'); |
||
64 | $cache->flushAll(); |
||
65 | |||
66 | $this->assertFalse($cache->contains('test_key1')); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<DoctrineModuleTes...aminasStorageCacheTest> .
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.
Loading history...
|
|||
67 | $this->assertFalse($cache->contains('test_key2')); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<DoctrineModuleTes...aminasStorageCacheTest> .
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.
Loading history...
|
|||
68 | } |
||
69 | |||
70 | public function testNamespace() : void |
||
71 | { |
||
72 | $cache = $this->getCacheDriver(); |
||
73 | $cache->setNamespace('test_'); |
||
74 | $cache->save('key1', 'test'); |
||
75 | |||
76 | $this->assertTrue($cache->contains('key1')); |
||
77 | |||
78 | $cache->setNamespace('test2_'); |
||
79 | |||
80 | $this->assertFalse($cache->contains('key1')); |
||
81 | } |
||
82 | |||
83 | public function testGetStats() : void |
||
84 | { |
||
85 | $cache = $this->getCacheDriver(); |
||
86 | $stats = $cache->getStats(); |
||
87 | |||
88 | $this->assertArrayHasKey(Cache::STATS_HITS, $stats); |
||
89 | $this->assertArrayHasKey(Cache::STATS_MISSES, $stats); |
||
90 | $this->assertArrayHasKey(Cache::STATS_UPTIME, $stats); |
||
91 | $this->assertArrayHasKey(Cache::STATS_MEMORY_USAGE, $stats); |
||
92 | $this->assertArrayHasKey(Cache::STATS_MEMORY_AVAILIABLE, $stats); |
||
93 | } |
||
94 | } |
||
95 |
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.