RegionTest.php 5.4 KB

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