OnlineTest.php 3.8 KB

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