2
0

MemcachedBackendTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. <?php
  2. /**
  3. * @package Zend_Cache
  4. * @subpackage UnitTests
  5. */
  6. /**
  7. * Zend_Cache
  8. */
  9. require_once 'Zend/Cache.php';
  10. require_once 'Zend/Cache/Backend/Memcached.php';
  11. /**
  12. * Common tests for backends
  13. */
  14. require_once 'CommonExtendedBackendTest.php';
  15. /**
  16. * PHPUnit test case
  17. */
  18. require_once 'PHPUnit/Framework/TestCase.php';
  19. /**
  20. * @package Zend_Cache
  21. * @subpackage UnitTests
  22. */
  23. class Zend_Cache_MemcachedBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  24. protected $_instance;
  25. public function __construct($name = null, array $data = array(), $dataName = '')
  26. {
  27. parent::__construct('Zend_Cache_Backend_Memcached', $data, $dataName);
  28. }
  29. public function setUp($notag = true)
  30. {
  31. $server = array(
  32. 'host' => TESTS_ZEND_CACHE_MEMCACHED_HOST,
  33. 'port' => TESTS_ZEND_CACHE_MEMCACHED_PORT,
  34. 'persistent' => TESTS_ZEND_CACHE_MEMCACHED_PERSISTENT
  35. );
  36. $options = array(
  37. 'servers' => array(0 => $server)
  38. );
  39. $this->_instance = new Zend_Cache_Backend_Memcached($options);
  40. parent::setUp($notag);
  41. }
  42. public function tearDown()
  43. {
  44. parent::tearDown();
  45. unset($this->_instance);
  46. // We have to wait after a memcache flush
  47. sleep(1);
  48. }
  49. public function testConstructorCorrectCall()
  50. {
  51. $test = new Zend_Cache_Backend_Memcached();
  52. }
  53. public function testCleanModeOld()
  54. {
  55. $this->_instance->setDirectives(array('logging' => false));
  56. $this->_instance->clean('old');
  57. // do nothing, just to see if an error occured
  58. $this->_instance->setDirectives(array('logging' => true));
  59. }
  60. public function testCleanModeMatchingTags()
  61. {
  62. $this->_instance->setDirectives(array('logging' => false));
  63. $this->_instance->clean('matchingTag', array('tag1'));
  64. // do nothing, just to see if an error occured
  65. $this->_instance->setDirectives(array('logging' => true));
  66. }
  67. public function testCleanModeNotMatchingTags()
  68. {
  69. $this->_instance->setDirectives(array('logging' => false));
  70. $this->_instance->clean('notMatchingTag', array('tag1'));
  71. // do nothing, just to see if an error occured
  72. $this->_instance->setDirectives(array('logging' => true));
  73. }
  74. public function testGetWithCompression()
  75. {
  76. $this->_instance->setOption('compression', true);
  77. $this->testGetWithAnExistingCacheIdAndUTFCharacters();
  78. }
  79. public function testConstructorWithAnAlternativeSyntax()
  80. {
  81. $server = array(
  82. 'host' => TESTS_ZEND_CACHE_MEMCACHED_HOST,
  83. 'port' => TESTS_ZEND_CACHE_MEMCACHED_PORT,
  84. 'persistent' => TESTS_ZEND_CACHE_MEMCACHED_PERSISTENT
  85. );
  86. $options = array(
  87. 'servers' => $server
  88. );
  89. $this->_instance = new Zend_Cache_Backend_Memcached($options);
  90. $this->testGetWithAnExistingCacheIdAndUTFCharacters();
  91. }
  92. // Because of limitations of this backend...
  93. public function testGetWithAnExpiredCacheId() {}
  94. public function testCleanModeMatchingTags2() {}
  95. public function testCleanModeNotMatchingTags2() {}
  96. public function testCleanModeNotMatchingTags3() {}
  97. public function testSaveCorrectCall()
  98. {
  99. $this->_instance->setDirectives(array('logging' => false));
  100. parent::testSaveCorrectCall();
  101. $this->_instance->setDirectives(array('logging' => true));
  102. }
  103. public function testSaveWithNullLifeTime()
  104. {
  105. $this->_instance->setDirectives(array('logging' => false));
  106. parent::testSaveWithNullLifeTime();
  107. $this->_instance->setDirectives(array('logging' => true));
  108. }
  109. public function testSaveWithSpecificLifeTime()
  110. {
  111. $this->_instance->setDirectives(array('logging' => false));
  112. parent::testSaveWithSpecificLifeTime();
  113. $this->_instance->setDirectives(array('logging' => true));
  114. }
  115. public function testGetMetadatas($notag = false)
  116. {
  117. parent::testGetMetadatas(true);
  118. }
  119. }