InstanceReservedTest.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. require_once 'Zend/Service/Amazon/Ec2/Instance/Reserved.php';
  3. require_once 'Zend/Http/Client.php';
  4. require_once 'Zend/Http/Client/Adapter/Test.php';
  5. require_once 'PHPUnit/Framework/TestCase.php';
  6. /**
  7. * Zend_Service_Amazon_Ec2_Instance_Reserved test case.
  8. */
  9. class InstanceReservedTest extends PHPUnit_Framework_TestCase
  10. {
  11. /**
  12. * @var Zend_Service_Amazon_Ec2_Instance_Reserved
  13. */
  14. private $Zend_Service_Amazon_Ec2_Instance_Reserved;
  15. /**
  16. * Prepares the environment before running a test.
  17. */
  18. protected function setUp()
  19. {
  20. parent::setUp();
  21. $this->Zend_Service_Amazon_Ec2_Instance_Reserved = new Zend_Service_Amazon_Ec2_Instance_Reserved('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_Instance_Reserved::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_Instance_Reserved = null;
  36. parent::tearDown();
  37. }
  38. /**
  39. * Tests Zend_Service_Amazon_Ec2_Instance_Reserved->describeInstances()
  40. */
  41. public function testDescribeInstances()
  42. {
  43. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  44. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  45. . "Server: hi\r\n"
  46. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  47. . "Status: 200 OK\r\n"
  48. . "Content-type: application/xml; charset=utf-8\r\n"
  49. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  50. . "Connection: close\r\n"
  51. . "\r\n"
  52. ."<DescribeReservedInstancesResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  53. ." <reservedInstancesSet>\r\n"
  54. ." <item>\r\n"
  55. ." <reservedInstancesId>4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8</reservedInstancesId>\r\n"
  56. ." <instanceType>m1.small</instanceType>\r\n"
  57. ." <availabilityZone>us-east-1a</availabilityZone>\r\n"
  58. ." <duration>12</duration>\r\n"
  59. ." <usagePrice>0.00</usagePrice>\r\n"
  60. ." <fixedPrice>0.00</fixedPrice>\r\n"
  61. ." <instanceCount>19</instanceCount>\r\n"
  62. ." <productDescription>m1.small offering in us-east-1a</productDescription>\r\n"
  63. ." <state>Active</state>\r\n"
  64. ." </item>\r\n"
  65. ." </reservedInstancesSet>\r\n"
  66. ."</DescribeReservedInstancesResponse>";
  67. $this->adapter->setResponse($rawHttpResponse);
  68. $return = $this->Zend_Service_Amazon_Ec2_Instance_Reserved->describeInstances('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8');
  69. $arrReturn = array(
  70. array(
  71. "reservedInstancesId" => "4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8",
  72. "instanceType" => "m1.small",
  73. "availabilityZone" => "us-east-1a",
  74. "duration" => "12",
  75. "fixedPrice" => "0.00",
  76. "usagePrice" => "0.00",
  77. "productDescription" => "m1.small offering in us-east-1a",
  78. "instanceCount" => "19",
  79. "state" => "Active"
  80. )
  81. );
  82. $this->assertSame($arrReturn, $return);
  83. }
  84. /**
  85. * Tests Zend_Service_Amazon_Ec2_Instance_Reserved->describeOfferings()
  86. */
  87. public function testDescribeOfferings()
  88. {
  89. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  90. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  91. . "Server: hi\r\n"
  92. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  93. . "Status: 200 OK\r\n"
  94. . "Content-type: application/xml; charset=utf-8\r\n"
  95. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  96. . "Connection: close\r\n"
  97. . "\r\n"
  98. ."<DescribeReservedInstancesOfferingsResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  99. ." <reservedInstancesOfferingsSet>\r\n"
  100. ." <item>\r\n"
  101. ." <reservedInstancesOfferingId>4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8</reservedInstancesOfferingId>\r\n"
  102. ." <instanceType>m1.small</instanceType>\r\n"
  103. ." <availabilityZone>us-east-1a</availabilityZone>\r\n"
  104. ." <duration>12</duration>\r\n"
  105. ." <usagePrice>0.00</usagePrice>\r\n"
  106. ." <fixedPrice>0.00</fixedPrice>\r\n"
  107. ." <productDescription>m1.small offering in us-east-1a</productDescription>\r\n"
  108. ." </item>\r\n"
  109. ." </reservedInstancesOfferingsSet>\r\n"
  110. ."</DescribeReservedInstancesOfferingsResponse>";
  111. $this->adapter->setResponse($rawHttpResponse);
  112. $return = $this->Zend_Service_Amazon_Ec2_Instance_Reserved->describeOfferings();
  113. $arrReturn = array(
  114. array(
  115. "reservedInstancesOfferingId" => "4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8",
  116. "instanceType" => "m1.small",
  117. "availabilityZone" => "us-east-1a",
  118. "duration" => "12",
  119. "fixedPrice" => "0.00",
  120. "usagePrice" => "0.00",
  121. "productDescription" => "m1.small offering in us-east-1a",
  122. )
  123. );
  124. $this->assertSame($arrReturn, $return);
  125. }
  126. /**
  127. * Tests Zend_Service_Amazon_Ec2_Instance_Reserved->purchaseOffering()
  128. */
  129. public function testPurchaseOffering()
  130. {
  131. $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
  132. . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  133. . "Server: hi\r\n"
  134. . "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
  135. . "Status: 200 OK\r\n"
  136. . "Content-type: application/xml; charset=utf-8\r\n"
  137. . "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
  138. . "Connection: close\r\n"
  139. . "\r\n"
  140. ."<PurchaseReservedInstancesOfferingResponse xmlns=\"http://ec2.amazonaws.com/doc/2009-04-04/\">\r\n"
  141. ." <reservedInstancesId>4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8</reservedInstancesId>\r\n"
  142. ."</PurchaseReservedInstancesOfferingResponse>";
  143. $this->adapter->setResponse($rawHttpResponse);
  144. $return = $this->Zend_Service_Amazon_Ec2_Instance_Reserved->purchaseOffering('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8');
  145. $this->assertSame('4b2293b4-5813-4cc8-9ce3-1957fc1dcfc8', $return);
  146. }
  147. }