MemcacheqTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_Queue
  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. * The adapter test class provides a universal test class for all of the
  24. * abstract methods.
  25. *
  26. * All methods marked not supported are explictly checked for for throwing
  27. * an exception.
  28. */
  29. /** Zend_Queue */
  30. require_once 'Zend/Queue.php';
  31. /** Zend_Queue */
  32. require_once 'Zend/Queue/Message.php';
  33. /** Zend_Queue_Message_Test */
  34. require_once 'MessageTestClass.php';
  35. /** Base Adapter test class */
  36. require_once dirname(__FILE__) . '/AdapterTest.php';
  37. /**
  38. * @category Zend
  39. * @package Zend_Queue
  40. * @subpackage UnitTests
  41. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  42. * @license http://framework.zend.com/license/new-bsd New BSD License
  43. * @group Zend_Queue
  44. */
  45. class Zend_Queue_Adapter_MemcacheqTest extends Zend_Queue_Adapter_AdapterTest
  46. {
  47. /**
  48. * Test setup
  49. */
  50. public function setUp()
  51. {
  52. if (!TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED) {
  53. $this->markTestSkipped('TESTS_ZEND_QUEUE_MEMCACHEQ_ENABLED is not enabled in TestConfiguration.php');
  54. }
  55. if (!extension_loaded('memcache')) {
  56. $this->markTestSkipped('memcache extension not loaded');
  57. }
  58. date_default_timezone_set('GMT');
  59. parent::setUp();
  60. }
  61. /**
  62. * getAdapterName() is an method to help make AdapterTest work with any
  63. * new adapters
  64. *
  65. * You must overload this method
  66. *
  67. * @return string
  68. */
  69. public function getAdapterName()
  70. {
  71. return 'Memcacheq';
  72. }
  73. /**
  74. * getAdapterName() is an method to help make AdapterTest work with any
  75. * new adapters
  76. *
  77. * You may overload this method. The default return is
  78. * 'Zend_Queue_Adapter_' . $this->getAdapterName()
  79. *
  80. * @return string
  81. */
  82. public function getAdapterFullName()
  83. {
  84. return 'Zend_Queue_Adapter_' . $this->getAdapterName();
  85. }
  86. public function getTestConfig()
  87. {
  88. $driverOptions = array();
  89. if (defined('TESTS_ZEND_QUEUE_MEMCACHEQ_HOST')) {
  90. $driverOptions['host'] = TESTS_ZEND_QUEUE_MEMCACHEQ_HOST;
  91. }
  92. if (defined('TESTS_ZEND_QUEUE_MEMCACHEQ_PORT')) {
  93. $driverOptions['port'] = TESTS_ZEND_QUEUE_MEMCACHEQ_PORT;
  94. }
  95. return array('driverOptions' => $driverOptions);
  96. }
  97. // test the constants
  98. public function testConst()
  99. {
  100. /**
  101. * @see Zend_Queue_Adapter_Memcacheq
  102. */
  103. require_once 'Zend/Queue/Adapter/Memcacheq.php';
  104. $this->assertTrue(is_string(Zend_Queue_Adapter_Memcacheq::DEFAULT_HOST));
  105. $this->assertTrue(is_integer(Zend_Queue_Adapter_Memcacheq::DEFAULT_PORT));
  106. $this->assertTrue(is_string(Zend_Queue_Adapter_Memcacheq::EOL));
  107. }
  108. /**
  109. * @group ZF-7650
  110. */
  111. public function testReceiveWillRetrieveZeroItems()
  112. {
  113. $options = array('name' => 'ZF7650', 'driverOptions' => $this->getTestConfig());
  114. $queue = new Zend_Queue('Memcacheq', $options);
  115. $queue2 = $queue->createQueue('queue');
  116. $queue->send('My Test Message 1');
  117. $queue->send('My Test Message 2');
  118. $messages = $queue->receive(0);
  119. $this->assertEquals(0, count($messages));
  120. }
  121. }