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

ArrayCacheTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A _getCacheDriver() 0 4 1
B testGetStats() 0 32 1
A isSharedStorage() 0 4 1
1
<?php
2
3
namespace Doctrine\Tests\Common\Cache;
4
5
use Doctrine\Common\Cache\ArrayCache;
6
use Doctrine\Common\Cache\Cache;
7
8
class ArrayCacheTest extends CacheTest
9
{
10
    protected function _getCacheDriver()
11
    {
12
        return new ArrayCache();
13
    }
14
15
    public function testGetStats()
16
    {
17
        $cache = $this->_getCacheDriver();
18
        $cache->fetch('test1');
19
        $cache->fetch('test2');
20
        $cache->fetch('test3');
21
22
        $cache->save('test1', 123);
23
        $cache->save('test2', 123);
24
25
        $cache->fetch('test1');
26
        $cache->fetch('test2');
27
        $cache->fetch('test3');
28
29
        $stats = $cache->getStats();
30
        $this->assertEquals(2, $stats[Cache::STATS_HITS]);
31
        $this->assertEquals(5, $stats[Cache::STATS_MISSES]); // +1 for internal call to DoctrineNamespaceCacheKey
32
        $this->assertNotNull($stats[Cache::STATS_UPTIME]);
33
        $this->assertNull($stats[Cache::STATS_MEMORY_USAGE]);
34
        $this->assertNull($stats[Cache::STATS_MEMORY_AVAILABLE]);
35
36
        $cache->delete('test1');
37
        $cache->delete('test2');
38
39
        $cache->fetch('test1');
40
        $cache->fetch('test2');
41
        $cache->fetch('test3');
42
43
        $stats = $cache->getStats();
44
        $this->assertEquals(2, $stats[Cache::STATS_HITS]);
45
        $this->assertEquals(8, $stats[Cache::STATS_MISSES]); // +1 for internal call to DoctrineNamespaceCacheKey
46
    }
47
48
    protected function isSharedStorage()
49
    {
50
        return false;
51
    }
52
}