OnlineTest.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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_Sqs
  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: OnlineTest.php 11973 2008-10-15 16:00:56Z matthew $
  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_Sqs
  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. */
  41. class Zend_Service_Amazon_Sqs_OnlineTest extends PHPUnit_Framework_TestCase
  42. {
  43. /**
  44. * Reference to Amazon service consumer object
  45. *
  46. * @var Zend_Service_Amazon_Sqs
  47. */
  48. protected $_amazon;
  49. /**
  50. * Socket based HTTP client adapter
  51. *
  52. * @var Zend_Http_Client_Adapter_Socket
  53. */
  54. protected $_httpClientAdapterSocket;
  55. /**
  56. * Sets up this test case
  57. *
  58. * @return void
  59. */
  60. public function setUp()
  61. {
  62. $this->_amazon = new Zend_Service_Amazon_Sqs(
  63. constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_ACCESSKEYID'),
  64. constant('TESTS_ZEND_SERVICE_AMAZON_ONLINE_SECRETKEY')
  65. );
  66. $this->_queue_name = constant('TESTS_ZEND_SERVICE_AMAZON_SQS_QUEUE');
  67. $this->_httpClientAdapterSocket = new Zend_Http_Client_Adapter_Socket();
  68. $this->_amazon->getHttpClient()
  69. ->setAdapter($this->_httpClientAdapterSocket);
  70. }
  71. /**
  72. * Test SQS methods
  73. *
  74. * @return void
  75. */
  76. public function testSqs()
  77. {
  78. try {
  79. $queue_url = $this->_amazon->create($this->_queue_name, 45);
  80. $timeout = $this->_amazon->getAttribute($queue_url, 'VisibilityTimeout');
  81. $this->assertEquals(45, $timeout, 'VisibilityTimeout attribute is not 45');
  82. $test_msg = 'this is a test';
  83. $this->_amazon->send($queue_url, $test_msg);
  84. $messages = $this->_amazon->receive($queue_url);
  85. foreach ($messages as $message) {
  86. $this->assertEquals($test_msg, $message['body']);
  87. }
  88. foreach ($messages as $message) {
  89. $result = $this->_amazon->deleteMessage($queue_url, $message['handle']);
  90. $this->assertTrue($result, 'Message was not deleted');
  91. }
  92. $count = $this->_amazon->count($queue_url);
  93. $this->assertEquals(0, $count);
  94. $this->_amazon->delete($queue_url);
  95. } catch (Exception $e) {
  96. $this->fail($e->getMessage());
  97. }
  98. }
  99. /**
  100. * Tear down the test case
  101. *
  102. * @return void
  103. */
  104. public function tearDown()
  105. {
  106. unset($this->_amazon);
  107. }
  108. }
  109. class Zend_Service_Amazon_Sqs_OnlineTest_Skip extends PHPUnit_Framework_TestCase
  110. {
  111. public function setUp()
  112. {
  113. $this->markTestSkipped(
  114. 'Zend_Service_Amazon_Sqs online tests not enabled with an access key ID in '
  115. . 'TestConfiguration.php'
  116. );
  117. }
  118. public function testNothing()
  119. {
  120. }
  121. }