DbTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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-2011 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-2011 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. protected function setUp()
  52. {
  53. date_default_timezone_set('GMT');
  54. }
  55. /**
  56. * getAdapterName() is an method to help make AdapterTest work with any
  57. * new adapters
  58. *
  59. * You must overload this method
  60. *
  61. * @return string
  62. */
  63. public function getAdapterName()
  64. {
  65. return 'Db';
  66. }
  67. /**
  68. * getAdapterName() is an method to help make AdapterTest work with any
  69. * new adapters
  70. *
  71. * You may overload this method. The default return is
  72. * 'Zend_Queue_Adapter_' . $this->getAdapterName()
  73. *
  74. * @return string
  75. */
  76. public function getAdapterFullName()
  77. {
  78. return 'Zend_Queue_Adapter_' . $this->getAdapterName();
  79. }
  80. public function getTestConfig()
  81. {
  82. $driverOptions = array();
  83. if (defined('TESTS_ZEND_QUEUE_DB')) {
  84. require_once 'Zend/Json.php';
  85. $driverOptions = Zend_Json::decode(TESTS_ZEND_QUEUE_DB);
  86. }
  87. return array(
  88. 'options' => array(Zend_Db_Select::FOR_UPDATE => true),
  89. 'driverOptions' => $driverOptions,
  90. );
  91. }
  92. // test the constants
  93. public function testConst()
  94. {
  95. $this->markTestSkipped('no constants to test');
  96. }
  97. // additional non-standard tests
  98. public function test_constructor2()
  99. {
  100. try {
  101. $config = $this->getTestConfig();
  102. /**
  103. * @see Zend_Db_Select
  104. */
  105. require_once 'Zend/Db/Select.php';
  106. $config['options'][Zend_Db_Select::FOR_UPDATE] = array();
  107. $queue = $this->createQueue(__FUNCTION__, $config);
  108. $this->fail('FOR_UPDATE accepted an array');
  109. } catch (Exception $e) {
  110. $this->assertTrue(true, 'FOR_UPDATE cannot be an array');
  111. }
  112. foreach (array('host', 'username', 'password', 'dbname') as $i => $arg) {
  113. try {
  114. $config = $this->getTestConfig();
  115. unset($config['driverOptions'][$arg]);
  116. $queue = $this->createQueue(__FUNCTION__, $config);
  117. $this->fail("$arg is required but was missing.");
  118. } catch (Exception $e) {
  119. $this->assertTrue(true, $arg . ' is required.');
  120. }
  121. }
  122. }
  123. }