ChainCacheTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace Doctrine\Tests\Common\Cache;
  3. use Doctrine\Common\Cache\ApcCache;
  4. use Doctrine\Common\Cache\ArrayCache;
  5. use Doctrine\Common\Cache\ChainCache;
  6. class ChainCacheTest extends CacheTest
  7. {
  8. protected function _getCacheDriver()
  9. {
  10. return new ChainCache(array(new ArrayCache()));
  11. }
  12. public function testLifetime()
  13. {
  14. $this->markTestSkipped('The ChainCache test uses ArrayCache which does not implement TTL currently.');
  15. }
  16. public function testGetStats()
  17. {
  18. $cache = $this->_getCacheDriver();
  19. $stats = $cache->getStats();
  20. $this->assertInternalType('array', $stats);
  21. }
  22. public function testOnlyFetchFirstOne()
  23. {
  24. $cache1 = new ArrayCache();
  25. $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
  26. $cache2->expects($this->never())->method('doFetch');
  27. $chainCache = new ChainCache(array($cache1, $cache2));
  28. $chainCache->save('id', 'bar');
  29. $this->assertEquals('bar', $chainCache->fetch('id'));
  30. }
  31. public function testFetchPropagateToFastestCache()
  32. {
  33. $cache1 = new ArrayCache();
  34. $cache2 = new ArrayCache();
  35. $cache2->save('bar', 'value');
  36. $chainCache = new ChainCache(array($cache1, $cache2));
  37. $this->assertFalse($cache1->contains('bar'));
  38. $result = $chainCache->fetch('bar');
  39. $this->assertEquals('value', $result);
  40. $this->assertTrue($cache2->contains('bar'));
  41. }
  42. public function testNamespaceIsPropagatedToAllProviders()
  43. {
  44. $cache1 = new ArrayCache();
  45. $cache2 = new ArrayCache();
  46. $chainCache = new ChainCache(array($cache1, $cache2));
  47. $chainCache->setNamespace('bar');
  48. $this->assertEquals('bar', $cache1->getNamespace());
  49. $this->assertEquals('bar', $cache2->getNamespace());
  50. }
  51. public function testDeleteToAllProviders()
  52. {
  53. $cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
  54. $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
  55. $cache1->expects($this->once())->method('doDelete');
  56. $cache2->expects($this->once())->method('doDelete');
  57. $chainCache = new ChainCache(array($cache1, $cache2));
  58. $chainCache->delete('bar');
  59. }
  60. public function testFlushToAllProviders()
  61. {
  62. $cache1 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
  63. $cache2 = $this->getMockForAbstractClass('Doctrine\Common\Cache\CacheProvider');
  64. $cache1->expects($this->once())->method('doFlush');
  65. $cache2->expects($this->once())->method('doFlush');
  66. $chainCache = new ChainCache(array($cache1, $cache2));
  67. $chainCache->flushAll();
  68. }
  69. protected function isSharedStorage()
  70. {
  71. return false;
  72. }
  73. }