Example #1
0
 public function testCallServiceDefinedRoot()
 {
     $this->service->rootUrl = "https://sample.example.com";
     $resource = new Google_Service_Resource($this->service, "test", "testResource", array("methods" => array("testMethod" => array("parameters" => array(), "path" => "method/path", "httpMethod" => "POST"))));
     $request = $resource->call("testMethod", array(array()));
     $this->assertEquals("https://sample.example.com/method/path?key=testKey", $request->getUrl());
     $this->assertEquals("POST", $request->getRequestMethod());
 }
 public function testAppEngineSslCerts()
 {
     $this->client->expects($this->once())->method("isAppEngine")->will($this->returnValue(true));
     $resource = new Google_Service_Resource($this->service, "test", "testResource", array("methods" => array("testMethod" => array("parameters" => array(), "path" => "method/path", "httpMethod" => "POST"))));
     $request = $resource->call("testMethod", array(array()));
     $this->assertEquals('/etc/ca-certificates.crt', $this->client->getHttpClient()->getDefaultOption('verify'));
 }
 public function testNoExpectedClassForAltMediaWithHttpFail()
 {
     // set the "alt" parameter to "media"
     $arguments = [['alt' => 'media']];
     $request = new Request('GET', '/?alt=media');
     $body = Stream::factory('thisisnotvalidjson');
     $response = new Response(300, [], $body);
     $http = $this->getMockBuilder("GuzzleHttp\\Client")->disableOriginalConstructor()->getMock();
     $http->expects($this->once())->method('send')->will($this->returnValue($response));
     $http->expects($this->any())->method('createRequest')->will($this->returnValue(new Request('GET', '/?alt=media')));
     $http->expects($this->once())->method('send')->will($this->returnValue($response));
     $client = new Google_Client();
     $client->setHttpClient($http);
     $service = new Test_Google_Service($client);
     // set up mock objects
     $resource = new Google_Service_Resource($service, "test", "testResource", array("methods" => array("testMethod" => array("parameters" => array(), "path" => "method/path", "httpMethod" => "POST"))));
     try {
         $expectedClass = 'ThisShouldBeIgnored';
         $decoded = $resource->call('testMethod', $arguments, $expectedClass);
         $this->fail('should have thrown exception');
     } catch (Google_Service_Exception $e) {
         $this->assertEquals('thisisnotvalidjson', $e->getMessage());
     }
 }
 public function testExceptionMessage()
 {
     // set the "alt" parameter to "media"
     $request = new Request('GET', '/');
     $errors = [["domain" => "foo"]];
     $body = Psr7\stream_for(json_encode(['error' => ['errors' => $errors]]));
     $response = new Response(400, [], $body);
     $http = $this->getMockBuilder("GuzzleHttp\\Client")->disableOriginalConstructor()->getMock();
     $http->expects($this->once())->method('send')->will($this->returnValue($response));
     if ($this->isGuzzle5()) {
         $http->expects($this->once())->method('createRequest')->will($this->returnValue(new GuzzleHttp\Message\Request('GET', '/?alt=media')));
     }
     $client = new Google_Client();
     $client->setHttpClient($http);
     $service = new Test_Google_Service($client);
     // set up mock objects
     $resource = new Google_Service_Resource($service, "test", "testResource", array("methods" => array("testMethod" => array("parameters" => array(), "path" => "method/path", "httpMethod" => "POST"))));
     try {
         $decoded = $resource->call('testMethod', array(array()));
         $this->fail('should have thrown exception');
     } catch (Google_Service_Exception $e) {
         $this->assertEquals($errors, $e->getErrors());
     }
 }