OnlineTest.php 3.8 KB

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