Completed
Push — master ( a8b991...dda2b8 )
by Marco
06:05 queued 02:56
created

ChainCacheTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 9
lcom 1
cbo 5
dl 0
loc 91
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A _getCacheDriver() 0 4 1
A testLifetime() 0 4 1
A testGetStats() 0 7 1
A testOnlyFetchFirstOne() 0 12 1
A testFetchPropagateToFastestCache() 0 16 1
A testNamespaceIsPropagatedToAllProviders() 0 11 1
A testDeleteToAllProviders() 0 11 1
A testFlushToAllProviders() 0 11 1
A isSharedStorage() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\Common\Cache;
4
5
use Doctrine\Common\Cache\ApcCache;
6
use Doctrine\Common\Cache\ArrayCache;
7
use Doctrine\Common\Cache\ChainCache;
8
9
class ChainCacheTest extends CacheTest
10
{
11
    protected function _getCacheDriver()
12
    {
13
        return new ChainCache(array(new ArrayCache()));
14
    }
15
16
    public function testLifetime()
17
    {
18
        $this->markTestSkipped('The ChainCache test uses ArrayCache which does not implement TTL currently.');
19
    }
20
21
    public function testGetStats()
22
    {
23
        $cache = $this->_getCacheDriver();
24
        $stats = $cache->getStats();
25
26
        $this->assertInternalType('array', $stats);
27
    }
28
29
    public function testOnlyFetchFirstOne()
30
    {
31
        $cache1 = new ArrayCache();
32
        $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
33
34
        $cache2->expects($this->never())->method('doFetch');
35
36
        $chainCache = new ChainCache(array($cache1, $cache2));
0 ignored issues
show
Documentation introduced by
array($cache1, $cache2) is of type array<integer,object<Doc...ckObject_MockObject>"}>, but the function expects a array<integer,object<Doc...n\Cache\CacheProvider>>.

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);
Loading history...
37
        $chainCache->save('id', 'bar');
38
39
        $this->assertEquals('bar', $chainCache->fetch('id'));
40
    }
41
42
    public function testFetchPropagateToFastestCache()
43
    {
44
        $cache1 = new ArrayCache();
45
        $cache2 = new ArrayCache();
46
47
        $cache2->save('bar', 'value');
48
49
        $chainCache = new ChainCache(array($cache1, $cache2));
50
51
        $this->assertFalse($cache1->contains('bar'));
52
53
        $result = $chainCache->fetch('bar');
54
55
        $this->assertEquals('value', $result);
56
        $this->assertTrue($cache2->contains('bar'));
57
    }
58
59
    public function testNamespaceIsPropagatedToAllProviders()
60
    {
61
        $cache1 = new ArrayCache();
62
        $cache2 = new ArrayCache();
63
64
        $chainCache = new ChainCache(array($cache1, $cache2));
65
        $chainCache->setNamespace('bar');
66
67
        $this->assertEquals('bar', $cache1->getNamespace());
68
        $this->assertEquals('bar', $cache2->getNamespace());
69
    }
70
71
    public function testDeleteToAllProviders()
72
    {
73
        $cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
74
        $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
75
76
        $cache1->expects($this->once())->method('doDelete');
77
        $cache2->expects($this->once())->method('doDelete');
78
79
        $chainCache = new ChainCache(array($cache1, $cache2));
80
        $chainCache->delete('bar');
81
    }
82
83
    public function testFlushToAllProviders()
84
    {
85
        $cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
86
        $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
87
88
        $cache1->expects($this->once())->method('doFlush');
89
        $cache2->expects($this->once())->method('doFlush');
90
91
        $chainCache = new ChainCache(array($cache1, $cache2));
92
        $chainCache->flushAll();
93
    }
94
95
    protected function isSharedStorage()
96
    {
97
        return false;
98
    }
99
}