~clinton-collins/familyproject/trunk

« back to all changes in this revision

Viewing changes to ZendFramework/tests/Zend/Service/Amazon/Ec2/RegionTest.php

  • Committer: Clinton Collins
  • Date: 2009-06-26 19:54:58 UTC
  • Revision ID: clinton.collins@gmail.com-20090626195458-5ebba0qcvo15xlpy
Initial Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
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';
 
7
 
 
8
/**
 
9
 * Zend_Service_Amazon_Ec2_Availabilityzones test case.
 
10
 */
 
11
class Zend_Service_Amazon_Ec2_RegionTest extends PHPUnit_Framework_TestCase
 
12
{
 
13
 
 
14
    /**
 
15
     * @var Zend_Service_Amazon_Ec2_Availabilityzones
 
16
     */
 
17
    private $Zend_Service_Amazon_Ec2_Region;
 
18
 
 
19
    /**
 
20
     * Prepares the environment before running a test.
 
21
     */
 
22
    protected function setUp()
 
23
    {
 
24
        parent::setUp();
 
25
 
 
26
        $this->Zend_Service_Amazon_Ec2_Region = new Zend_Service_Amazon_Ec2_Region('access_key', 'secret_access_key');
 
27
 
 
28
        $adapter = new Zend_Http_Client_Adapter_Test();
 
29
        $client = new Zend_Http_Client(null, array(
 
30
            'adapter' => $adapter
 
31
        ));
 
32
        $this->adapter = $adapter;
 
33
        Zend_Service_Amazon_Ec2_Region::setHttpClient($client);
 
34
 
 
35
    }
 
36
 
 
37
    /**
 
38
     * Cleans up the environment after running a test.
 
39
     */
 
40
    protected function tearDown()
 
41
    {
 
42
        unset($this->adapter);
 
43
 
 
44
        $this->Zend_Service_Amazon_Ec2_Availabilityzones = null;
 
45
 
 
46
        parent::tearDown();
 
47
    }
 
48
 
 
49
    public function testDescribeSingleRegion()
 
50
    {
 
51
        $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
 
52
                    . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
 
53
                    . "Server: hi\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"
 
59
                    . "\r\n"
 
60
                    . "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2008-12-01/\">\r\n"
 
61
                    . "  <regionInfo>\r\n"
 
62
                    . "    <item>\r\n"
 
63
                    . "      <regionName>us-east-1</regionName>\r\n"
 
64
                    . "      <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n"
 
65
                    . "    </item>\r\n"
 
66
                    . "  </regionInfo>\r\n"
 
67
                    . "</DescribeRegionsResponse>";
 
68
        $this->adapter->setResponse($rawHttpResponse);
 
69
 
 
70
        $response = $this->Zend_Service_Amazon_Ec2_Region->describe('us-east-1');
 
71
 
 
72
        $arrRegion = array(
 
73
            array(
 
74
                'regionName'    => 'us-east-1',
 
75
                'regionUrl'     => 'us-east-1.ec2.amazonaws.com'
 
76
            )
 
77
        );
 
78
 
 
79
        $this->assertSame($arrRegion, $response);
 
80
    }
 
81
 
 
82
    public function testDescribeMultipleRegions()
 
83
    {
 
84
        $rawHttpResponse = "HTTP/1.1 200 OK\r\n"
 
85
                    . "Date: Fri, 24 Oct 2008 17:24:52 GMT\r\n"
 
86
                    . "Server: hi\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"
 
92
                    . "\r\n"
 
93
                    . "<DescribeRegionsResponse xmlns=\"http://ec2.amazonaws.com/doc/2008-12-01/\">\r\n"
 
94
                    . "  <regionInfo>\r\n"
 
95
                    . "    <item>\r\n"
 
96
                    . "      <regionName>us-east-1</regionName>\r\n"
 
97
                    . "      <regionUrl>us-east-1.ec2.amazonaws.com</regionUrl>\r\n"
 
98
                    . "    </item>\r\n"
 
99
                    . "    <item>\r\n"
 
100
                    . "      <regionName>us-west-1</regionName>\r\n"
 
101
                    . "      <regionUrl>us-west-1.ec2.amazonaws.com</regionUrl>\r\n"
 
102
                    . "    </item>\r\n"
 
103
                    . "  </regionInfo>\r\n"
 
104
                    . "</DescribeRegionsResponse>";
 
105
        $this->adapter->setResponse($rawHttpResponse);
 
106
 
 
107
        $response = $this->Zend_Service_Amazon_Ec2_Region->describe(array('us-east-1','us-west-1'));
 
108
 
 
109
        $arrRegion = array(
 
110
            array(
 
111
                'regionName'    => 'us-east-1',
 
112
                'regionUrl'     => 'us-east-1.ec2.amazonaws.com'
 
113
            ),
 
114
            array(
 
115
                'regionName'    => 'us-west-1',
 
116
                'regionUrl'     => 'us-west-1.ec2.amazonaws.com'
 
117
            )
 
118
        );
 
119
 
 
120
        $this->assertSame($arrRegion, $response);
 
121
    }
 
122
}
 
123