CacheProviderTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. class CacheProviderTest extends \Doctrine\Tests\DoctrineTestCase
  4. {
  5. public function testFetchMultiWillFilterNonRequestedKeys()
  6. {
  7. /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
  8. $cache = $this->getMockForAbstractClass(
  9. 'Doctrine\Common\Cache\CacheProvider',
  10. array(),
  11. '',
  12. true,
  13. true,
  14. true,
  15. array('doFetchMultiple')
  16. );
  17. $cache
  18. ->expects($this->once())
  19. ->method('doFetchMultiple')
  20. ->will($this->returnValue(array(
  21. '[foo][1]' => 'bar',
  22. '[bar][1]' => 'baz',
  23. '[baz][1]' => 'tab',
  24. )));
  25. $this->assertEquals(
  26. array('foo' => 'bar', 'bar' => 'baz'),
  27. $cache->fetchMultiple(array('foo', 'bar'))
  28. );
  29. }
  30. public function testFailedDeleteAllDoesNotChangeNamespaceVersion()
  31. {
  32. /* @var $cache \Doctrine\Common\Cache\CacheProvider|\PHPUnit_Framework_MockObject_MockObject */
  33. $cache = $this->getMockForAbstractClass(
  34. 'Doctrine\Common\Cache\CacheProvider',
  35. array(),
  36. '',
  37. true,
  38. true,
  39. true,
  40. array('doFetch', 'doSave', 'doContains')
  41. );
  42. $cache
  43. ->expects($this->once())
  44. ->method('doFetch')
  45. ->with('DoctrineNamespaceCacheKey[]')
  46. ->will($this->returnValue(false));
  47. // doSave is only called once from deleteAll as we do not need to persist the default version in getNamespaceVersion()
  48. $cache
  49. ->expects($this->once())
  50. ->method('doSave')
  51. ->with('DoctrineNamespaceCacheKey[]')
  52. ->will($this->returnValue(false));
  53. // After a failed deleteAll() the local namespace version is not increased (still 1). Otherwise all data written afterwards
  54. // would be lost outside the current instance.
  55. $cache
  56. ->expects($this->once())
  57. ->method('doContains')
  58. ->with('[key][1]')
  59. ->will($this->returnValue(true));
  60. $this->assertFalse($cache->deleteAll(), 'deleteAll() returns false when saving the namespace version fails');
  61. $cache->contains('key');
  62. }
  63. }