3
require_once 'PHPUnit/Framework/TestCase.php';
4
require_once 'Zend/Http/Client.php';
5
require_once 'Zend/Http/Client/Adapter/Test.php';
6
require_once 'Zend/Service/Amazon/Ec2/Region.php';
9
* Zend_Service_Amazon_Ec2_Availabilityzones test case.
11
class Zend_Service_Amazon_Ec2_RegionTest extends PHPUnit_Framework_TestCase
15
* @var Zend_Service_Amazon_Ec2_Availabilityzones
17
private $Zend_Service_Amazon_Ec2_Region;
20
* Prepares the environment before running a test.
22
protected function setUp()
26
$this->Zend_Service_Amazon_Ec2_Region = new Zend_Service_Amazon_Ec2_Region('access_key', 'secret_access_key');
28
$adapter = new Zend_Http_Client_Adapter_Test();
29
$client = new Zend_Http_Client(null, array(
32
$this->adapter = $adapter;
33
Zend_Service_Amazon_Ec2_Region::setHttpClient($client);
38
* Cleans up the environment after running a test.
40
protected function tearDown()
42
unset($this->adapter);
44
$this->Zend_Service_Amazon_Ec2_Availabilityzones = null;
49
public function testDescribeSingleRegion()
51
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
52
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
54
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
55
. "Status: 200 OK\r\n"
56
. "Content-type: application/xml; charset=utf-8\r\n"
57
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
58
. "Connection: close\r\n"
60
. "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2008-12-01/\">\r\n"
63
. " <regionName>us-east-1</regionName>\r\n"
64
. " <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n"
66
. " </regionInfo>\r\n"
67
. "</DescribeRegionsResponse>";
68
$this->adapter->setResponse($rawHttpResponse);
70
$response = $this->Zend_Service_Amazon_Ec2_Region->describe('us-east-1');
74
'regionName' => 'us-east-1',
75
'regionUrl' => 'us-east-1.ec2.amazonaws.com'
79
$this->assertSame($arrRegion, $response);
82
public function testDescribeMultipleRegions()
84
$rawHttpResponse = "HTTP/1.1 200 OK\r\n"
85
. "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
87
. "Last-modified: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
88
. "Status: 200 OK\r\n"
89
. "Content-type: application/xml; charset=utf-8\r\n"
90
. "Expires: Tue, 31 Mar 1981 05:00:00 GMT\r\n"
91
. "Connection: close\r\n"
93
. "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2008-12-01/\">\r\n"
96
. " <regionName>us-east-1</regionName>\r\n"
97
. " <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n"
100
. " <regionName>us-west-1</regionName>\r\n"
101
. " <regionUrl>us-west-1.ec2.amazonaws.com</regionUrl>\r\n"
103
. " </regionInfo>\r\n"
104
. "</DescribeRegionsResponse>";
105
$this->adapter->setResponse($rawHttpResponse);
107
$response = $this->Zend_Service_Amazon_Ec2_Region->describe(array('us-east-1','us-west-1'));
111
'regionName' => 'us-east-1',
112
'regionUrl' => 'us-east-1.ec2.amazonaws.com'
115
'regionName' => 'us-west-1',
116
'regionUrl' => 'us-west-1.ec2.amazonaws.com'
120
$this->assertSame($arrRegion, $response);