3 namespace Doctrine\Tests\Common\Cache;
5 use Doctrine\Common\Cache\ApcCache;
6 use Doctrine\Common\Cache\ArrayCache;
7 use Doctrine\Common\Cache\ChainCache;
9 class ChainCacheTest extends CacheTest
11 protected function _getCacheDriver()
13 return new ChainCache(array(new ArrayCache()));
16 public function testLifetime()
18 $this->markTestSkipped('The ChainCache test uses ArrayCache which does not implement TTL currently.');
21 public function testGetStats()
23 $cache = $this->_getCacheDriver();
24 $stats = $cache->getStats();
26 $this->assertInternalType('array', $stats);
29 public function testOnlyFetchFirstOne()
31 $cache1 = new ArrayCache();
32 $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
34 $cache2->expects($this->never())->method('doFetch');
36 $chainCache = new ChainCache(array($cache1, $cache2));
37 $chainCache->save('id', 'bar');
39 $this->assertEquals('bar', $chainCache->fetch('id'));
42 public function testFetchPropagateToFastestCache()
44 $cache1 = new ArrayCache();
45 $cache2 = new ArrayCache();
47 $cache2->save('bar', 'value');
49 $chainCache = new ChainCache(array($cache1, $cache2));
51 $this->assertFalse($cache1->contains('bar'));
53 $result = $chainCache->fetch('bar');
55 $this->assertEquals('value', $result);
56 $this->assertTrue($cache2->contains('bar'));
59 public function testNamespaceIsPropagatedToAllProviders()
61 $cache1 = new ArrayCache();
62 $cache2 = new ArrayCache();
64 $chainCache = new ChainCache(array($cache1, $cache2));
65 $chainCache->setNamespace('bar');
67 $this->assertEquals('bar', $cache1->getNamespace());
68 $this->assertEquals('bar', $cache2->getNamespace());
71 public function testDeleteToAllProviders()
73 $cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
74 $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
76 $cache1->expects($this->once())->method('doDelete');
77 $cache2->expects($this->once())->method('doDelete');
79 $chainCache = new ChainCache(array($cache1, $cache2));
80 $chainCache->delete('bar');
83 public function testFlushToAllProviders()
85 $cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
86 $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
88 $cache1->expects($this->once())->method('doFlush');
89 $cache2->expects($this->once())->method('doFlush');
91 $chainCache = new ChainCache(array($cache1, $cache2));
92 $chainCache->flushAll();
95 protected function isSharedStorage()