OnlineTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_Service_Amazon
  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. require_once 'Zend/Service/Amazon/Sqs.php';
  23. require_once 'Zend/Http/Client/Adapter/Socket.php';
  24. /**
  25. * @category Zend
  26. * @package Zend_Service_Amazon
  27. * @subpackage UnitTests
  28. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  29. * @license http://framework.zend.com/license/new-bsd New BSD License
  30. * @group Zend_Service
  31. * @group Zend_Service_Amazon
  32. * @group Zend_Service_Amazon_Sqs
  33. */
  34. class Zend_Service_Amazon_Sqs_OnlineTest extends PHPUnit_Framework_TestCase
  35. {
  36. /**
  37. * Reference to Amazon service consumer object
  38. *
  39. * @var Zend_Service_Amazon_Sqs
  40. */
  41. protected $_amazon;
  42. /**
  43. * Socket based HTTP client adapter
  44. *
  45. * @var Zend_Http_Client_Adapter_Socket
  46. */
  47. protected $_httpClientAdapterSocket;
  48. /**
  49. * Sets up this test case
  50. *
  51. * @return void
  52. */
  53. public function setUp()
  54. {
  55. $this->_amazon = new Zend_Service_Amazon_Sqs(
  56. constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
  57. constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')
  58. );
  59. $this->_queue_name = constant('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE');
  60. $this->_httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
  61. $this->_amazon->getHttpClient()
  62. ->setAdapter($this->_httpClientAdapterSocket);
  63. }
  64. /**
  65. * Test SQS methods
  66. *
  67. * @return void
  68. */
  69. public function testSqs()
  70. {
  71. try {
  72. $queue_url = $this->_amazon->create($this->_queue_name, 45);
  73. $timeout = $this->_amazon->getAttribute($queue_url, 'VisibilityTimeout');
  74. $this->assertEquals(45, $timeout, 'VisibilityTimeout attribute is not 45');
  75. $test_msg = 'this is a test';
  76. $this->_amazon->send($queue_url, $test_msg);
  77. $messages = $this->_amazon->receive($queue_url);
  78. foreach ($messages as $message) {
  79. $this->assertEquals($test_msg, $message['body']);
  80. }
  81. foreach ($messages as $message) {
  82. $result = $this->_amazon->deleteMessage($queue_url, $message['handle']);
  83. $this->assertTrue($result, 'Message was not deleted');
  84. }
  85. $count = $this->_amazon->count($queue_url);
  86. $this->assertEquals(0, $count);
  87. $this->_amazon->delete($queue_url);
  88. } catch (Exception $e) {
  89. $this->fail($e->getMessage());
  90. }
  91. }
  92. /**
  93. * Tear down the test case
  94. *
  95. * @return void
  96. */
  97. public function tearDown()
  98. {
  99. unset($this->_amazon);
  100. }
  101. }
  102. class Zend_Service_Amazon_Sqs_OnlineTest_Skip extends PHPUnit_Framework_TestCase
  103. {
  104. public function setUp()
  105. {
  106. $this->markTestSkipped(
  107. 'Zend_Service_Amazon_Sqs online tests not enabled with an access key ID in '
  108. . 'TestConfiguration.php'
  109. );
  110. }
  111. public function testNothing()
  112. {
  113. }
  114. }