MemcachedBackendTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Cache
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * Zend_Cache
  24. */
  25. require_once 'Zend/Cache.php';
  26. require_once 'Zend/Cache/Backend/Memcached.php';
  27. /**
  28. * Common tests for backends
  29. */
  30. require_once 'CommonExtendedBackendTest.php';
  31. /**
  32. * @category Zend
  33. * @package Zend_Cache
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_Cache
  38. */
  39. class Zend_Cache_MemcachedBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  40. protected $_instance;
  41. public function __construct($name = null, array $data = array(), $dataName = '')
  42. {
  43. parent::__construct('Zend_Cache_Backend_Memcached', $data, $dataName);
  44. }
  45. public function setUp($notag = true)
  46. {
  47. if(!class_exists('Memcached')) {
  48. $this->markTestSkipped('Memcached is not installed, skipping test');
  49. return;
  50. }
  51. $serverValid = array(
  52. 'host' => TESTS_ZEND_CACHE_MEMCACHED_HOST,
  53. 'port' => TESTS_ZEND_CACHE_MEMCACHED_PORT,
  54. 'persistent' => TESTS_ZEND_CACHE_MEMCACHED_PERSISTENT
  55. );
  56. $serverFail = array(
  57. 'host' => 'not.exist',
  58. 'port' => TESTS_ZEND_CACHE_MEMCACHED_PORT,
  59. 'persistent' => TESTS_ZEND_CACHE_MEMCACHED_PERSISTENT
  60. );
  61. $options = array(
  62. 'servers' => array($serverValid, $serverFail)
  63. );
  64. $this->_instance = new Zend_Cache_Backend_Memcached($options);
  65. parent::setUp($notag);
  66. }
  67. public function tearDown()
  68. {
  69. parent::tearDown();
  70. unset($this->_instance);
  71. // We have to wait after a memcache flush
  72. sleep(1);
  73. }
  74. public function testConstructorCorrectCall()
  75. {
  76. $test = new Zend_Cache_Backend_Memcached();
  77. }
  78. public function testCleanModeOld()
  79. {
  80. $this->_instance->setDirectives(array('logging' => false));
  81. $this->_instance->clean('old');
  82. // do nothing, just to see if an error occured
  83. $this->_instance->setDirectives(array('logging' => true));
  84. }
  85. public function testCleanModeMatchingTags()
  86. {
  87. $this->_instance->setDirectives(array('logging' => false));
  88. $this->_instance->clean('matchingTag', array('tag1'));
  89. // do nothing, just to see if an error occured
  90. $this->_instance->setDirectives(array('logging' => true));
  91. }
  92. public function testCleanModeNotMatchingTags()
  93. {
  94. $this->_instance->setDirectives(array('logging' => false));
  95. $this->_instance->clean('notMatchingTag', array('tag1'));
  96. // do nothing, just to see if an error occured
  97. $this->_instance->setDirectives(array('logging' => true));
  98. }
  99. public function testGetWithCompression()
  100. {
  101. $this->_instance->setOption('compression', true);
  102. $this->testGetWithAnExistingCacheIdAndUTFCharacters();
  103. }
  104. public function testConstructorWithAnAlternativeSyntax()
  105. {
  106. $server = array(
  107. 'host' => TESTS_ZEND_CACHE_MEMCACHED_HOST,
  108. 'port' => TESTS_ZEND_CACHE_MEMCACHED_PORT,
  109. 'persistent' => TESTS_ZEND_CACHE_MEMCACHED_PERSISTENT
  110. );
  111. $options = array(
  112. 'servers' => $server
  113. );
  114. $this->_instance = new Zend_Cache_Backend_Memcached($options);
  115. $this->testGetWithAnExistingCacheIdAndUTFCharacters();
  116. }
  117. // Because of limitations of this backend...
  118. public function testGetWithAnExpiredCacheId() {}
  119. public function testCleanModeMatchingTags2() {}
  120. public function testCleanModeNotMatchingTags2() {}
  121. public function testCleanModeNotMatchingTags3() {}
  122. public function testSaveCorrectCall()
  123. {
  124. $this->_instance->setDirectives(array('logging' => false));
  125. parent::testSaveCorrectCall();
  126. $this->_instance->setDirectives(array('logging' => true));
  127. }
  128. public function testSaveWithNullLifeTime()
  129. {
  130. $this->_instance->setDirectives(array('logging' => false));
  131. parent::testSaveWithNullLifeTime();
  132. $this->_instance->setDirectives(array('logging' => true));
  133. }
  134. public function testSaveWithSpecificLifeTime()
  135. {
  136. $this->_instance->setDirectives(array('logging' => false));
  137. parent::testSaveWithSpecificLifeTime();
  138. $this->_instance->setDirectives(array('logging' => true));
  139. }
  140. public function testGetMetadatas($notag = false)
  141. {
  142. parent::testGetMetadatas(true);
  143. }
  144. public function testGetFillingPercentage()
  145. {
  146. $this->_instance->setDirectives(array('logging' => false));
  147. parent::testGetFillingPercentage();
  148. }
  149. public function testGetFillingPercentageOnEmptyBackend()
  150. {
  151. $this->_instance->setDirectives(array('logging' => false));
  152. parent::testGetFillingPercentageOnEmptyBackend();
  153. }
  154. }