SqsTest.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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_Cloud_QueueService
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. // Call Zend_Cloud_QueueService_Adapter_SqsTest::main() if this source file is executed directly.
  22. if (!defined("PHPUnit_MAIN_METHOD")) {
  23. define("PHPUnit_MAIN_METHOD", "Zend_Cloud_QueueService_Adapter_SqsTest::main");
  24. }
  25. require_once dirname(__FILE__) . '/../../../../TestHelper.php';
  26. /**
  27. * @see Zend_Cloud_QueueServiceTestCase
  28. */
  29. require_once 'Zend/Cloud/QueueService/TestCase.php';
  30. /**
  31. * @see Zend_Cloud_QueueeService_Adapter_Sqs
  32. */
  33. require_once 'Zend/Cloud/QueueService/Adapter/Sqs.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Cloud
  37. * @subpackage UnitTests
  38. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. */
  41. class Zend_Cloud_QueueService_Adapter_SqsTest extends Zend_Cloud_QueueService_TestCase
  42. {
  43. /**
  44. * Period to wait for propagation in seconds
  45. * Should be set by adapter
  46. *
  47. * @var int
  48. */
  49. protected $_waitPeriod = 10;
  50. protected $_clientType = 'Zend_Service_Amazon_Sqs';
  51. /**
  52. * Runs the test methods of this class.
  53. *
  54. * @access public
  55. * @static
  56. */
  57. public static function main()
  58. {
  59. $suite = new PHPUnit_Framework_TestSuite(__CLASS__);
  60. $result = PHPUnit_TextUI_TestRunner::run($suite);
  61. }
  62. /**
  63. * Sets up this test case
  64. *
  65. * @return void
  66. */
  67. public function setUp()
  68. {
  69. parent::setUp();
  70. // Isolate the tests from slow deletes
  71. $this->_wait();
  72. }
  73. public function testListQueues()
  74. {
  75. try {
  76. $queues = $this->_commonQueue->listQueues();
  77. $this->_wait();
  78. if (count($queues)) {
  79. foreach ($queues as $queue) {
  80. $this->_commonQueue->deleteQueue($queue);
  81. $this->_wait();
  82. }
  83. }
  84. $queueURL1 = $this->_commonQueue->createQueue('test-list-queue1');
  85. $this->assertNotNull($queueURL1);
  86. $this->_wait();
  87. $queueURL2 = $this->_commonQueue->createQueue('test-list-queue2');
  88. $this->assertNotNull($queueURL2);
  89. // Wait 30s after creation to ensure we can retrieve it
  90. $this->_wait(30);
  91. $queues = $this->_commonQueue->listQueues();
  92. $errorMessage = "Final queues are ";
  93. foreach ($queues as $queue) {
  94. $errorMessage .= $queue . ', ';
  95. }
  96. $errorMessage .= "\nHave queue URLs $queueURL1 and $queueURL2\n";
  97. $this->assertEquals(2, count($queues), $errorMessage);
  98. // PHPUnit does an identical comparison for assertContains(), so we just
  99. // use assertTrue and in_array()
  100. $this->assertTrue(in_array($queueURL1, $queues));
  101. $this->assertTrue(in_array($queueURL2, $queues));
  102. $this->_commonQueue->deleteQueue($queueURL1);
  103. $this->_commonQueue->deleteQueue($queueURL2);
  104. } catch (Exception $e) {
  105. if (isset($queueURL1)) {
  106. $this->_commonQueue->deleteQueue($queueURL1);
  107. }
  108. if (isset($queueURL2)) {
  109. $this->_commonQueue->deleteQueue($queueURL2);
  110. }
  111. throw $e;
  112. }
  113. }
  114. public function testStoreQueueMetadata() {
  115. $this->markTestSkipped('SQS does not currently support storing metadata');
  116. }
  117. protected function _getConfig()
  118. {
  119. if (!defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')
  120. || !constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ENABLED')
  121. || !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID')
  122. || !defined('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')
  123. ) {
  124. $this->markTestSkipped("Amazon SQS access not configured, skipping test");
  125. }
  126. $config = new Zend_Config(array(
  127. Zend_Cloud_QueueService_Factory::QUEUE_ADAPTER_KEY => 'Zend_Cloud_QueueService_Adapter_Sqs',
  128. Zend_Cloud_QueueService_Adapter_Sqs::AWS_ACCESS_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
  129. Zend_Cloud_QueueService_Adapter_Sqs::AWS_SECRET_KEY => constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY'),
  130. ));
  131. return $config;
  132. }
  133. }
  134. if (PHPUnit_MAIN_METHOD == 'Zend_Cloud_QueueService_Adapter_SqsTest::main') {
  135. Zend_Cloud_QueueService_Adapter_SqsTest::main();
  136. }