AvailabilityzonesTest.php 5.4 KB

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