|
18 | 18 | * under the License. |
19 | 19 | */ |
20 | 20 |
|
| 21 | +use GuzzleHttp\Message\Request; |
| 22 | +use GuzzleHttp\Message\Response; |
| 23 | +use GuzzleHttp\Stream\Stream; |
| 24 | + |
21 | 25 | class Test_Google_Service extends Google_Service |
22 | 26 | { |
23 | 27 | public function __construct(Google_Client $client) |
@@ -193,4 +197,95 @@ public function testAppEngineSslCerts() |
193 | 197 | $this->client->getHttpClient()->getDefaultOption('verify') |
194 | 198 | ); |
195 | 199 | } |
| 200 | + |
| 201 | + public function testNoExpectedClassForAltMediaWithHttpSuccess() |
| 202 | + { |
| 203 | + // set the "alt" parameter to "media" |
| 204 | + $arguments = [['alt' => 'media']]; |
| 205 | + $request = new Request('GET', '/?alt=media'); |
| 206 | + $body = Stream::factory('thisisnotvalidjson'); |
| 207 | + $response = new Response(200, [], $body); |
| 208 | + |
| 209 | + $http = $this->getMockBuilder("GuzzleHttp\Client") |
| 210 | + ->disableOriginalConstructor() |
| 211 | + ->getMock(); |
| 212 | + $http->expects($this->once()) |
| 213 | + ->method('send') |
| 214 | + ->will($this->returnValue($response)); |
| 215 | + $http->expects($this->any()) |
| 216 | + ->method('createRequest') |
| 217 | + ->will($this->returnValue($request)); |
| 218 | + $client = new Google_Client(); |
| 219 | + $client->setHttpClient($http); |
| 220 | + $service = new Test_Google_Service($client); |
| 221 | + |
| 222 | + // set up mock objects |
| 223 | + $resource = new Google_Service_Resource( |
| 224 | + $service, |
| 225 | + "test", |
| 226 | + "testResource", |
| 227 | + array("methods" => |
| 228 | + array( |
| 229 | + "testMethod" => array( |
| 230 | + "parameters" => array(), |
| 231 | + "path" => "method/path", |
| 232 | + "httpMethod" => "POST", |
| 233 | + ) |
| 234 | + ) |
| 235 | + ) |
| 236 | + ); |
| 237 | + |
| 238 | + $expectedClass = 'ThisShouldBeIgnored'; |
| 239 | + $decoded = $resource->call('testMethod', $arguments, $expectedClass); |
| 240 | + $this->assertEquals('thisisnotvalidjson', $decoded); |
| 241 | + } |
| 242 | + |
| 243 | + public function testNoExpectedClassForAltMediaWithHttpFail() |
| 244 | + { |
| 245 | + // set the "alt" parameter to "media" |
| 246 | + $arguments = [['alt' => 'media']]; |
| 247 | + $request = new Request('GET', '/?alt=media'); |
| 248 | + $body = Stream::factory('thisisnotvalidjson'); |
| 249 | + $response = new Response(300, [], $body); |
| 250 | + |
| 251 | + $http = $this->getMockBuilder("GuzzleHttp\Client") |
| 252 | + ->disableOriginalConstructor() |
| 253 | + ->getMock(); |
| 254 | + $http->expects($this->once()) |
| 255 | + ->method('send') |
| 256 | + ->will($this->returnValue($response)); |
| 257 | + $http->expects($this->any()) |
| 258 | + ->method('createRequest') |
| 259 | + ->will($this->returnValue(new Request('GET', '/?alt=media'))); |
| 260 | + $http->expects($this->once()) |
| 261 | + ->method('send') |
| 262 | + ->will($this->returnValue($response)); |
| 263 | + $client = new Google_Client(); |
| 264 | + $client->setHttpClient($http); |
| 265 | + $service = new Test_Google_Service($client); |
| 266 | + |
| 267 | + // set up mock objects |
| 268 | + $resource = new Google_Service_Resource( |
| 269 | + $service, |
| 270 | + "test", |
| 271 | + "testResource", |
| 272 | + array("methods" => |
| 273 | + array( |
| 274 | + "testMethod" => array( |
| 275 | + "parameters" => array(), |
| 276 | + "path" => "method/path", |
| 277 | + "httpMethod" => "POST", |
| 278 | + ) |
| 279 | + ) |
| 280 | + ) |
| 281 | + ); |
| 282 | + |
| 283 | + try { |
| 284 | + $expectedClass = 'ThisShouldBeIgnored'; |
| 285 | + $decoded = $resource->call('testMethod', $arguments, $expectedClass); |
| 286 | + $this->fail('should have thrown exception'); |
| 287 | + } catch (Google_Service_Exception $e) { |
| 288 | + $this->assertEquals('thisisnotvalidjson', $e->getMessage()); |
| 289 | + } |
| 290 | + } |
196 | 291 | } |
0 commit comments