RegionTest.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. require_once 'PHPUnit/Framework/TestCase.php';
  23. require_once 'Zend/Http/Client.php';
  24. require_once 'Zend/Http/Client/Adapter/Test.php';
  25. require_once 'Zend/Service/Amazon/Ec2/Region.php';
  26. /**
  27. * Zend_Service_Amazon_Ec2_Region test case.
  28. *
  29. * @category Zend
  30. * @package Zend_Service_Amazon
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Service
  35. * @group Zend_Service_Amazon
  36. * @group Zend_Service_Amazon_Ec2
  37. */
  38. class Zend_Service_Amazon_Ec2_RegionTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * @var Zend_Service_Amazon_Ec2_Availabilityzones
  42. */
  43. private $Zend_Service_Amazon_Ec2_Region;
  44. /**
  45. * Prepares the environment before running a test.
  46. */
  47. protected function setUp()
  48. {
  49. parent::setUp();
  50. $this->Zend_Service_Amazon_Ec2_Region = new Zend_Service_Amazon_Ec2_Region('access_key', 'secret_access_key');
  51. $adapter = new Zend_Http_Client_Adapter_Test();
  52. $client = new Zend_Http_Client(null, array(
  53. 'adapter' => $adapter
  54. ));
  55. $this->adapter = $adapter;
  56. Zend_Service_Amazon_Ec2_Region::setHttpClient($client);
  57. }
  58. /**
  59. * Cleans up the environment after running a test.
  60. */
  61. protected function tearDown()
  62. {
  63. unset($this->adapter);
  64. $this->Zend_Service_Amazon_Ec2_Availabilityzones = null;
  65. parent::tearDown();
  66. }
  67. public function testDescribeSingleRegion()
  68. {
  69. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  70. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  71. . "Server: hi\r\n"
  72. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  73. . "Status: 200 OK\r\n"
  74. . "Content-type: application/xml; charset=utf-8\r\n"
  75. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  76. . "Connection: close\r\n"
  77. . "\r\n"
  78. . "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  79. . " <regionInfo>\r\n"
  80. . " <item>\r\n"
  81. . " <regionName>us-east-1</regionName>\r\n"
  82. . " <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n"
  83. . " </item>\r\n"
  84. . " </regionInfo>\r\n"
  85. . "</DescribeRegionsResponse>";
  86. $this->adapter->setResponse($rawHttpResponse);
  87. $response = $this->Zend_Service_Amazon_Ec2_Region->describe('us-east-1');
  88. $arrRegion = array(
  89. array(
  90. 'regionName' => 'us-east-1',
  91. 'regionUrl' => 'us-east-1.ec2.amazonaws.com'
  92. )
  93. );
  94. $this->assertSame($arrRegion, $response);
  95. }
  96. public function testDescribeMultipleRegions()
  97. {
  98. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  99. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  100. . "Server: hi\r\n"
  101. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  102. . "Status: 200 OK\r\n"
  103. . "Content-type: application/xml; charset=utf-8\r\n"
  104. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  105. . "Connection: close\r\n"
  106. . "\r\n"
  107. . "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  108. . " <regionInfo>\r\n"
  109. . " <item>\r\n"
  110. . " <regionName>us-east-1</regionName>\r\n"
  111. . " <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n"
  112. . " </item>\r\n"
  113. . " <item>\r\n"
  114. . " <regionName>us-west-1</regionName>\r\n"
  115. . " <regionUrl>us-west-1.ec2.amazonaws.com</regionUrl>\r\n"
  116. . " </item>\r\n"
  117. . " </regionInfo>\r\n"
  118. . "</DescribeRegionsResponse>";
  119. $this->adapter->setResponse($rawHttpResponse);
  120. $response = $this->Zend_Service_Amazon_Ec2_Region->describe(array('us-east-1','us-west-1'));
  121. $arrRegion = array(
  122. array(
  123. 'regionName' => 'us-east-1',
  124. 'regionUrl' => 'us-east-1.ec2.amazonaws.com'
  125. ),
  126. array(
  127. 'regionName' => 'us-west-1',
  128. 'regionUrl' => 'us-west-1.ec2.amazonaws.com'
  129. )
  130. );
  131. $this->assertSame($arrRegion, $response);
  132. }
  133. }