RegionTest.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. require_once 'PHPUnit/Framework/TestCase.php';
  3. require_once 'Zend/Http/Client.php';
  4. require_once 'Zend/Http/Client/Adapter/Test.php';
  5. require_once 'Zend/Service/Amazon/Ec2/Region.php';
  6. /**
  7. * Zend_Service_Amazon_Ec2_Availabilityzones test case.
  8. */
  9. class Zend_Service_Amazon_Ec2_RegionTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @var Zend_Service_Amazon_Ec2_Availabilityzones
  13. */
  14. private $Zend_Service_Amazon_Ec2_Region;
  15. /**
  16. * Prepares the environment before running a test.
  17. */
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. $this->Zend_Service_Amazon_Ec2_Region = new Zend_Service_Amazon_Ec2_Region('access_key', 'secret_access_key');
  22. $adapter = new Zend_Http_Client_Adapter_Test();
  23. $client = new Zend_Http_Client(null, array(
  24. 'adapter' => $adapter
  25. ));
  26. $this->adapter = $adapter;
  27. Zend_Service_Amazon_Ec2_Region::setHttpClient($client);
  28. }
  29. /**
  30. * Cleans up the environment after running a test.
  31. */
  32. protected function tearDown()
  33. {
  34. unset($this->adapter);
  35. $this->Zend_Service_Amazon_Ec2_Availabilityzones = null;
  36. parent::tearDown();
  37. }
  38. public function testDescribeSingleRegion()
  39. {
  40. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  41. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  42. . "Server: hi\r\n"
  43. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  44. . "Status: 200 OK\r\n"
  45. . "Content-type: application/xml; charset=utf-8\r\n"
  46. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  47. . "Connection: close\r\n"
  48. . "\r\n"
  49. . "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  50. . " <regionInfo>\r\n"
  51. . " <item>\r\n"
  52. . " <regionName>us-east-1</regionName>\r\n"
  53. . " <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n"
  54. . " </item>\r\n"
  55. . " </regionInfo>\r\n"
  56. . "</DescribeRegionsResponse>";
  57. $this->adapter->setResponse($rawHttpResponse);
  58. $response = $this->Zend_Service_Amazon_Ec2_Region->describe('us-east-1');
  59. $arrRegion = array(
  60. array(
  61. 'regionName' => 'us-east-1',
  62. 'regionUrl' => 'us-east-1.ec2.amazonaws.com'
  63. )
  64. );
  65. $this->assertSame($arrRegion, $response);
  66. }
  67. public function testDescribeMultipleRegions()
  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. . " <item>\r\n"
  85. . " <regionName>us-west-1</regionName>\r\n"
  86. . " <regionUrl>us-west-1.ec2.amazonaws.com</regionUrl>\r\n"
  87. . " </item>\r\n"
  88. . " </regionInfo>\r\n"
  89. . "</DescribeRegionsResponse>";
  90. $this->adapter->setResponse($rawHttpResponse);
  91. $response = $this->Zend_Service_Amazon_Ec2_Region->describe(array('us-east-1','us-west-1'));
  92. $arrRegion = array(
  93. array(
  94. 'regionName' => 'us-east-1',
  95. 'regionUrl' => 'us-east-1.ec2.amazonaws.com'
  96. ),
  97. array(
  98. 'regionName' => 'us-west-1',
  99. 'regionUrl' => 'us-west-1.ec2.amazonaws.com'
  100. )
  101. );
  102. $this->assertSame($arrRegion, $response);
  103. }
  104. }