AvailabilityzonesTest.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/Availabilityzones.php';
  26. /**
  27. * Zend_Service_Amazon_Ec2_Availabilityzones 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_AvailabilityzonesTest extends PHPUnit_Framework_TestCase
  39. {
  40. /**
  41. * @var Zend_Service_Amazon_Ec2_Availabilityzones
  42. */
  43. private $Zend_Service_Amazon_Ec2_Availabilityzones;
  44. /**
  45. * Prepares the environment before running a test.
  46. */
  47. protected function setUp()
  48. {
  49. parent::setUp();
  50. $this->Zend_Service_Amazon_Ec2_Availabilityzones = new Zend_Service_Amazon_Ec2_Availabilityzones('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_Availabilityzones::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 testDescribeSingleAvailabilityZone()
  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. . "<DescribeAvailabilityZonesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  79. . " <availabilityZoneInfo>\r\n"
  80. . " <item>\r\n"
  81. . " <zoneName>us-east-1a</zoneName>\r\n"
  82. . " <zoneState>available</zoneState>\r\n"
  83. . " </item>\r\n"
  84. . " </availabilityZoneInfo>\r\n"
  85. . "</DescribeAvailabilityZonesResponse>";
  86. $this->adapter->setResponse($rawHttpResponse);
  87. $response = $this->Zend_Service_Amazon_Ec2_Availabilityzones->describe('us-east-1a');
  88. $this->assertType('array', $response);
  89. $this->assertEquals('us-east-1a', $response[0]['zoneName']);
  90. $this->assertEquals('available', $response[0]['zoneState']);
  91. }
  92. public function testDescribeMultipleAvailabilityZones()
  93. {
  94. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  95. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  96. . "Server: hi\r\n"
  97. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  98. . "Status: 200 OK\r\n"
  99. . "Content-type: application/xml; charset=utf-8\r\n"
  100. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  101. . "Connection: close\r\n"
  102. . "\r\n"
  103. . "<DescribeAvailabilityZonesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  104. . " <availabilityZoneInfo>\r\n"
  105. . " <item>\r\n"
  106. . " <zoneName>us-east-1a</zoneName>\r\n"
  107. . " <zoneState>available</zoneState>\r\n"
  108. . " </item>\r\n"
  109. . " <item>\r\n"
  110. . " <zoneName>us-east-1b</zoneName>\r\n"
  111. . " <zoneState>available</zoneState>\r\n"
  112. . " </item>\r\n"
  113. . " <item>\r\n"
  114. . " <zoneName>us-east-1c</zoneName>\r\n"
  115. . " <zoneState>available</zoneState>\r\n"
  116. . " </item>\r\n"
  117. . " </availabilityZoneInfo>\r\n"
  118. . "</DescribeAvailabilityZonesResponse>";
  119. $this->adapter->setResponse($rawHttpResponse);
  120. $response = $this->Zend_Service_Amazon_Ec2_Availabilityzones->describe();
  121. $this->assertType('array', $response);
  122. $arrExpected = array('us-east-1a', 'us-east-1b', 'us-east-1c');
  123. foreach ($response as $k => $node) {
  124. $this->assertEquals($arrExpected[$k], $node['zoneName']);
  125. }
  126. }
  127. }