2222require_once 'Google/Http/Request.php ' ;
2323require_once 'Google/IO/Stream.php ' ;
2424
25- class IoTest extends BaseTest {
26-
27- public function testStreamParseHttpResponseBody () {
25+ class IoTest extends BaseTest
26+ {
27+
28+ public function testStreamParseHttpResponseBody ()
29+ {
2830 $ io = new Google_IO_Stream ($ this ->getClient ());
2931 $ this ->responseChecker ($ io );
3032 }
3133
32- public function testStreamProcessEntityRequest () {
34+ public function testStreamProcessEntityRequest ()
35+ {
3336 $ client = $ this ->getClient ();
3437 $ io = new Google_IO_Stream ($ client );
3538 $ this ->processEntityRequest ($ io , $ client );
3639 }
37-
38- public function testStreamCacheHit () {
40+
41+ public function testStreamCacheHit ()
42+ {
3943 $ client = $ this ->getClient ();
4044 $ io = new Google_IO_Stream ($ client );
4145 $ this ->cacheHit ($ io , $ client );
4246 }
43-
44- public function testStreamAuthCache () {
47+
48+ public function testStreamAuthCache ()
49+ {
4550 $ client = $ this ->getClient ();
4651 $ io = new Google_IO_Stream ($ client );
4752 $ this ->authCache ($ io , $ client );
4853 }
49-
54+
5055 /**
5156 * @expectedException Google_IO_Exception
5257 */
53- public function testInvalidRequest () {
58+ public function testInvalidRequest ()
59+ {
5460 $ io = new Google_IO_Stream ($ this ->getClient ());
5561 $ url = "http://localhost:1 " ;
5662 $ req = new Google_Http_Request ($ url , "GET " );
5763 $ io ->makeRequest ($ req );
5864 }
5965
6066 // Asserting Functions
61-
62- public function cacheHit ($ io , $ client ) {
67+
68+ public function cacheHit ($ io , $ client )
69+ {
6370 $ url = "http://www.googleapis.com " ;
6471 // Create a cacheable request/response.
6572 // Should not be revalidated.
6673 $ cacheReq = new Google_Http_Request ($ url , "GET " );
67- $ cacheReq ->setRequestHeaders (array (
68- "Accept " => "*/* " ,
69- )) ;
74+ $ cacheReq ->setRequestHeaders (
75+ array ( "Accept " => "*/* " ,)
76+ );
7077 $ cacheReq ->setResponseBody ("{ \"a \": \"foo \"} " );
7178 $ cacheReq ->setResponseHttpCode (200 );
72- $ cacheReq ->setResponseHeaders (array (
73- "Cache-Control " => "private " ,
74- "ETag " => "\"this-is-an-etag \"" ,
75- "Expires " => "Sun, 22 Jan 2022 09:00:56 GMT " ,
76- "Date " => "Sun, 1 Jan 2012 09:00:56 GMT " ,
77- "Content-Type " => "application/json; charset=UTF-8 " ,
78- ));
79+ $ cacheReq ->setResponseHeaders (
80+ array (
81+ "Cache-Control " => "private " ,
82+ "ETag " => "\"this-is-an-etag \"" ,
83+ "Expires " => "Sun, 22 Jan 2022 09:00:56 GMT " ,
84+ "Date " => "Sun, 1 Jan 2012 09:00:56 GMT " ,
85+ "Content-Type " => "application/json; charset=UTF-8 " ,
86+ )
87+ );
7988
8089 // Populate the cache.
8190 $ io ->setCachedRequest ($ cacheReq );
@@ -86,30 +95,36 @@ public function cacheHit($io, $client) {
8695 $ this ->assertEquals (200 , $ res ->getResponseHttpCode ());
8796 }
8897
89- public function authCache ($ io , $ client ) {
98+ public function authCache ($ io , $ client )
99+ {
90100 $ url = "http://www.googleapis.com/protected/resource " ;
91101
92102 // Create a cacheable request/response, but it should not be cached.
93103 $ cacheReq = new Google_Http_Request ($ url , "GET " );
94- $ cacheReq ->setRequestHeaders (array (
95- "Accept " => "*/* " ,
96- "Authorization " => "Bearer Foo "
97- ));
104+ $ cacheReq ->setRequestHeaders (
105+ array (
106+ "Accept " => "*/* " ,
107+ "Authorization " => "Bearer Foo "
108+ )
109+ );
98110 $ cacheReq ->setResponseBody ("{ \"a \": \"foo \"} " );
99111 $ cacheReq ->setResponseHttpCode (200 );
100- $ cacheReq ->setResponseHeaders (array (
101- "Cache-Control " => "private " ,
102- "ETag " => "\"this-is-an-etag \"" ,
103- "Expires " => "Sun, 22 Jan 2022 09:00:56 GMT " ,
104- "Date: Sun, 1 Jan 2012 09:00:56 GMT " ,
105- "Content-Type " => "application/json; charset=UTF-8 " ,
106- ));
112+ $ cacheReq ->setResponseHeaders (
113+ array (
114+ "Cache-Control " => "private " ,
115+ "ETag " => "\"this-is-an-etag \"" ,
116+ "Expires " => "Sun, 22 Jan 2022 09:00:56 GMT " ,
117+ "Date: Sun, 1 Jan 2012 09:00:56 GMT " ,
118+ "Content-Type " => "application/json; charset=UTF-8 " ,
119+ )
120+ );
107121
108122 $ result = $ io ->setCachedRequest ($ cacheReq );
109123 $ this ->assertFalse ($ result );
110124 }
111-
112- public function responseChecker ($ io ) {
125+
126+ public function responseChecker ($ io )
127+ {
113128 $ rawHeaders = "HTTP/1.1 200 OK \r\n"
114129 . "Expires: Sun, 22 Jan 2012 09:00:56 GMT \r\n"
115130 . "Date: Sun, 22 Jan 2012 09:00:56 GMT \r\n"
@@ -140,7 +155,8 @@ public function responseChecker($io) {
140155 $ this ->assertEquals (array (), json_decode ($ body , true ));
141156 }
142157
143- public function processEntityRequest ($ io , $ client ) {
158+ public function processEntityRequest ($ io , $ client )
159+ {
144160 $ req = new Google_Http_Request ("http://localhost.com " );
145161 $ req ->setRequestMethod ("POST " );
146162
@@ -163,17 +179,21 @@ public function processEntityRequest($io, $client) {
163179 $ req ->setPostBody (array ("a " => "1 " , "b " => 2 ));
164180 $ io ->processEntityRequest ($ req );
165181 $ this ->assertEquals (7 , $ req ->getRequestHeader ("content-length " ));
166- $ this ->assertEquals (Google_IO_Abstract::FORM_URLENCODED ,
167- $ req ->getRequestHeader ("content-type " ));
182+ $ this ->assertEquals (
183+ Google_IO_Abstract::FORM_URLENCODED ,
184+ $ req ->getRequestHeader ("content-type " )
185+ );
168186 $ this ->assertEquals ("a=1&b=2 " , $ req ->getPostBody ());
169187
170188 // Verify that the content-type isn't reset.
171189 $ payload = array ("a " => "1 " , "b " => 2 );
172190 $ req ->setPostBody ($ payload );
173191 $ req ->setRequestHeaders (array ("content-type " => "multipart/form-data " ));
174192 $ io ->processEntityRequest ($ req );
175- $ this ->assertEquals ("multipart/form-data " ,
176- $ req ->getRequestHeader ("content-type " ));
193+ $ this ->assertEquals (
194+ "multipart/form-data " ,
195+ $ req ->getRequestHeader ("content-type " )
196+ );
177197 $ this ->assertEquals ($ payload , $ req ->getPostBody ());
178198 }
179199}
0 commit comments