LibmemcachedBackendTest.php 5.4 KB

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