3 namespace Doctrine\Tests\Common\Cache;
5 class CacheProviderTest extends \Doctrine\Tests\DoctrineTestCase
7 public function testFetchMultiWillFilterNonRequestedKeys()
9 /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
10 $cache = $this->getMockForAbstractClass(
11 'Doctrine\Common\Cache\CacheProvider',
17 array('doFetchMultiple')
21 ->expects($this->once())
22 ->method('doFetchMultiple')
23 ->will($this->returnValue(array(
30 array('foo' => 'bar', 'bar' => 'baz'),
31 $cache->fetchMultiple(array('foo', 'bar'))
35 public function testFailedDeleteAllDoesNotChangeNamespaceVersion()
37 /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
38 $cache = $this->getMockForAbstractClass(
39 'Doctrine\Common\Cache\CacheProvider',
45 array('doFetch', 'doSave', 'doContains')
49 ->expects($this->once())
51 ->with('DoctrineNamespaceCacheKey[]')
52 ->will($this->returnValue(false));
54 // doSave is only called once from deleteAll as we do not need to persist the default version in getNamespaceVersion()
56 ->expects($this->once())
58 ->with('DoctrineNamespaceCacheKey[]')
59 ->will($this->returnValue(false));
61 // After a failed deleteAll() the local namespace version is not increased (still 1). Otherwise all data written afterwards
62 // would be lost outside the current instance.
64 ->expects($this->once())
65 ->method('doContains')
67 ->will($this->returnValue(true));
69 $this->assertFalse($cache->deleteAll(), 'deleteAll() returns false when saving the namespace version fails');
70 $cache->contains('key');
73 public function testSaveMultipleNoFail()
75 /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
76 $cache = $this->getMockForAbstractClass(
77 'Doctrine\Common\Cache\CacheProvider',
87 ->expects($this->at(1))
89 ->with('[kerr][1]', 'verr', 0)
90 ->will($this->returnValue(false));
93 ->expects($this->at(2))
95 ->with('[kok][1]', 'vok', 0)
96 ->will($this->returnValue(true));
98 $cache->saveMultiple(array(