DbTest.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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-2009 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. /** TestHelp.php */
  30. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  31. /** Zend_Queue */
  32. require_once 'Zend/Queue.php';
  33. /** Zend_Queue */
  34. require_once 'Zend/Queue/Message.php';
  35. /** Zend_Queue_Message_Test */
  36. require_once 'MessageTestClass.php';
  37. /** Base Adapter test class */
  38. require_once dirname(__FILE__) . '/AdapterTest.php';
  39. /**
  40. * @see Zend_Db_Select
  41. */
  42. require_once 'Zend/Db/Select.php';
  43. /**
  44. * @category Zend
  45. * @package Zend_Queue
  46. * @subpackage UnitTests
  47. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  48. * @license http://framework.zend.com/license/new-bsd New BSD License
  49. * @group Zend_Queue
  50. */
  51. class Zend_Queue_Adapter_DbTest extends Zend_Queue_Adapter_AdapterTest
  52. {
  53. protected function setUp()
  54. {
  55. date_default_timezone_set('GMT');
  56. }
  57. /**
  58. * getAdapterName() is an method to help make AdapterTest work with any
  59. * new adapters
  60. *
  61. * You must overload this method
  62. *
  63. * @return string
  64. */
  65. public function getAdapterName()
  66. {
  67. return 'Db';
  68. }
  69. /**
  70. * getAdapterName() is an method to help make AdapterTest work with any
  71. * new adapters
  72. *
  73. * You may overload this method. The default return is
  74. * 'Zend_Queue_Adapter_' . $this->getAdapterName()
  75. *
  76. * @return string
  77. */
  78. public function getAdapterFullName()
  79. {
  80. return 'Zend_Queue_Adapter_' . $this->getAdapterName();
  81. }
  82. public function getTestConfig()
  83. {
  84. $driverOptions = array();
  85. if (defined('TESTS_ZEND_QUEUE_DB')) {
  86. require_once 'Zend/Json.php';
  87. $driverOptions = Zend_Json::decode(TESTS_ZEND_QUEUE_DB);
  88. }
  89. return array(
  90. 'options' => array(Zend_Db_Select::FOR_UPDATE => true),
  91. 'driverOptions' => $driverOptions,
  92. );
  93. }
  94. // test the constants
  95. public function testConst()
  96. {
  97. $this->markTestSkipped('no constants to test');
  98. }
  99. // additional non-standard tests
  100. public function test_constructor2()
  101. {
  102. try {
  103. $config = $this->getTestConfig();
  104. /**
  105. * @see Zend_Db_Select
  106. */
  107. require_once 'Zend/Db/Select.php';
  108. $config['options'][Zend_Db_Select::FOR_UPDATE] = array();
  109. $queue = $this->createQueue(__FUNCTION__, $config);
  110. $this->fail('FOR_UPDATE accepted an array');
  111. } catch (Exception $e) {
  112. $this->assertTrue(true, 'FOR_UPDATE cannot be an array');
  113. }
  114. foreach (array('host', 'username', 'password', 'dbname') as $i => $arg) {
  115. try {
  116. $config = $this->getTestConfig();
  117. unset($config['driverOptions'][$arg]);
  118. $queue = $this->createQueue(__FUNCTION__, $config);
  119. $this->fail("$arg is required but was missing.");
  120. } catch (Exception $e) {
  121. $this->assertTrue(true, $arg . ' is required.');
  122. }
  123. }
  124. }
  125. }