SqsTest.php 5.0 KB

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