DbTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. * @see Zend_Db_Select
  39. */
  40. require_once 'Zend/Db/Select.php';
  41. /**
  42. * @category Zend
  43. * @package Zend_Queue
  44. * @subpackage UnitTests
  45. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  46. * @license http://framework.zend.com/license/new-bsd New BSD License
  47. * @group Zend_Queue
  48. */
  49. class Zend_Queue_Adapter_DbTest extends Zend_Queue_Adapter_AdapterTest
  50. {
  51. /**
  52. * Test setup
  53. */
  54. public function setUp()
  55. {
  56. if (!TESTS_ZEND_QUEUE_DB) {
  57. $this->markTestSkipped('TESTS_ZEND_QUEUE_DB is not enabled in TestConfiguration.php');
  58. }
  59. date_default_timezone_set('GMT');
  60. parent::setUp();
  61. }
  62. /**
  63. * getAdapterName() is an method to help make AdapterTest work with any
  64. * new adapters
  65. *
  66. * You must overload this method
  67. *
  68. * @return string
  69. */
  70. public function getAdapterName()
  71. {
  72. return 'Db';
  73. }
  74. /**
  75. * getAdapterName() is an method to help make AdapterTest work with any
  76. * new adapters
  77. *
  78. * You may overload this method. The default return is
  79. * 'Zend_Queue_Adapter_' . $this->getAdapterName()
  80. *
  81. * @return string
  82. */
  83. public function getAdapterFullName()
  84. {
  85. return 'Zend_Queue_Adapter_' . $this->getAdapterName();
  86. }
  87. public function getTestConfig()
  88. {
  89. $driverOptions = array();
  90. if (defined('TESTS_ZEND_QUEUE_DB')) {
  91. require_once 'Zend/Json.php';
  92. $driverOptions = Zend_Json::decode(TESTS_ZEND_QUEUE_DB);
  93. }
  94. return array(
  95. 'options' => array(Zend_Db_Select::FOR_UPDATE => true),
  96. 'driverOptions' => $driverOptions,
  97. );
  98. }
  99. // test the constants
  100. public function testConst()
  101. {
  102. $this->markTestSkipped('no constants to test');
  103. }
  104. // additional non-standard tests
  105. public function test_constructor2()
  106. {
  107. try {
  108. $config = $this->getTestConfig();
  109. /**
  110. * @see Zend_Db_Select
  111. */
  112. require_once 'Zend/Db/Select.php';
  113. $config['options'][Zend_Db_Select::FOR_UPDATE] = array();
  114. $queue = $this->createQueue(__FUNCTION__, $config);
  115. $this->fail('FOR_UPDATE accepted an array');
  116. } catch (Exception $e) {
  117. $this->assertTrue(true, 'FOR_UPDATE cannot be an array');
  118. }
  119. foreach (array('host', 'username', 'password', 'dbname') as $i => $arg) {
  120. try {
  121. $config = $this->getTestConfig();
  122. unset($config['driverOptions'][$arg]);
  123. $queue = $this->createQueue(__FUNCTION__, $config);
  124. $this->fail("$arg is required but was missing.");
  125. } catch (Exception $e) {
  126. $this->assertTrue(true, $arg . ' is required.');
  127. }
  128. }
  129. }
  130. /**
  131. * @group ZF-7650
  132. */
  133. public function testReceiveWillRetrieveZeroItems()
  134. {
  135. $options = $this->getTestConfig();
  136. $options['name'] = '/temp-queue/ZF7650';
  137. $queue = new Zend_Queue('Db', $options);
  138. $queue2 = $queue->createQueue('queue');
  139. $queue->send('My Test Message 1');
  140. $queue->send('My Test Message 2');
  141. $messages = $queue->receive(0);
  142. $this->assertEquals(0, count($messages));
  143. }
  144. }