LibmemcachedBackendTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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/Libmemcached.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_LibmemcachedBackendTest extends Zend_Cache_CommonExtendedBackendTest {
  40. protected $_instance;
  41. public function __construct($name = null, array $data = array(), $dataName = '')
  42. {
  43. parent::__construct('Zend_Cache_Backend_Libmemcached', $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_LIBMEMCACHED_HOST,
  53. 'port' => TESTS_ZEND_CACHE_LIBMEMCACHED_PORT,
  54. 'weight' => TESTS_ZEND_CACHE_LIBMEMCACHED_WEIGHT
  55. );
  56. $options = array(
  57. 'servers' => array($serverValid),
  58. 'client' => array(
  59. 'no_block' => false, // set Memcached client option by name
  60. Memcached::OPT_TCP_NODELAY => false, // set Memcached client option by value
  61. ),
  62. );
  63. $this->_instance = new Zend_Cache_Backend_Libmemcached($options);
  64. parent::setUp($notag);
  65. }
  66. public function tearDown()
  67. {
  68. parent::tearDown();
  69. $this->_instance = null;
  70. // We have to wait after a memcached flush
  71. sleep(1);
  72. }
  73. public function testConstructorCorrectCall()
  74. {
  75. $test = new Zend_Cache_Backend_Libmemcached();
  76. }
  77. public function testCleanModeOld()
  78. {
  79. $this->_instance->setDirectives(array('logging' => false));
  80. $this->_instance->clean('old');
  81. // do nothing, just to see if an error occured
  82. $this->_instance->setDirectives(array('logging' => true));
  83. }
  84. public function testCleanModeMatchingTags()
  85. {
  86. $this->_instance->setDirectives(array('logging' => false));
  87. $this->_instance->clean('matchingTag', array('tag1'));
  88. // do nothing, just to see if an error occured
  89. $this->_instance->setDirectives(array('logging' => true));
  90. }
  91. public function testCleanModeNotMatchingTags()
  92. {
  93. $this->_instance->setDirectives(array('logging' => false));
  94. $this->_instance->clean('notMatchingTag', array('tag1'));
  95. // do nothing, just to see if an error occured
  96. $this->_instance->setDirectives(array('logging' => true));
  97. }
  98. public function testGetWithCompression()
  99. {
  100. $this->_instance->setOption('compression', true);
  101. $this->testGetWithAnExistingCacheIdAndUTFCharacters();
  102. }
  103. public function testConstructorWithAnAlternativeSyntax()
  104. {
  105. $server = array(
  106. 'host' => TESTS_ZEND_CACHE_LIBMEMCACHED_HOST,
  107. 'port' => TESTS_ZEND_CACHE_LIBMEMCACHED_PORT,
  108. 'weight' => TESTS_ZEND_CACHE_LIBMEMCACHED_WEIGHT
  109. );
  110. $options = array(
  111. 'servers' => $server
  112. );
  113. $this->_instance = new Zend_Cache_Backend_Libmemcached($options);
  114. $this->testGetWithAnExistingCacheIdAndUTFCharacters();
  115. }
  116. // Because of limitations of this backend...
  117. public function testGetWithAnExpiredCacheId() {}
  118. public function testCleanModeMatchingTags2() {}
  119. public function testCleanModeNotMatchingTags2() {}
  120. public function testCleanModeNotMatchingTags3() {}
  121. public function testSaveCorrectCall()
  122. {
  123. $this->_instance->setDirectives(array('logging' => false));
  124. parent::testSaveCorrectCall();
  125. $this->_instance->setDirectives(array('logging' => true));
  126. }
  127. public function testSaveWithNullLifeTime()
  128. {
  129. $this->_instance->setDirectives(array('logging' => false));
  130. parent::testSaveWithNullLifeTime();
  131. $this->_instance->setDirectives(array('logging' => true));
  132. }
  133. public function testSaveWithSpecificLifeTime()
  134. {
  135. $this->_instance->setDirectives(array('logging' => false));
  136. parent::testSaveWithSpecificLifeTime();
  137. $this->_instance->setDirectives(array('logging' => true));
  138. }
  139. public function testGetMetadatas($notag = false)
  140. {
  141. parent::testGetMetadatas(true);
  142. }
  143. public function testGetFillingPercentage()
  144. {
  145. $this->_instance->setDirectives(array('logging' => false));
  146. parent::testGetFillingPercentage();
  147. }
  148. public function testGetFillingPercentageOnEmptyBackend()
  149. {
  150. $this->_instance->setDirectives(array('logging' => false));
  151. parent::testGetFillingPercentageOnEmptyBackend();
  152. }
  153. }