public function prepare() { $request = parent::prepare(); if (null !== ($url = $this->get('url'))) { $request->setUrl($url); } return $request; }
/** * add the template variables to the query part * * @return \Guzzle\Http\Message\RequestInterface */ public function prepare() { $request = parent::prepare(); $url = $request->getUrl(true); $query = $url->getQuery(); $query->merge($this->templateVariables); $request->setUrl($url); return $request; }
public function testAddsContentTypeWhenExpectsIsSetOnCommand() { $op = new OperationCommand(array(), new Operation()); $op['command.expects'] = 'application/json'; $op->setClient(new Client()); $request = $op->prepare(); $request->setResponse(new Response(200, null, '{"Baz":"Bar"}'), true); $this->assertEquals(array('Baz' => 'Bar'), $op->execute()); }
public function testAllowsRawResponses() { $description = new ServiceDescription(array('operations' => array('foo' => array('responseClass' => 'bar', 'responseType' => 'model')), 'models' => array('bar' => array()))); $op = new OperationCommand(array(OperationCommand::RESPONSE_PROCESSING => OperationCommand::TYPE_RAW), $description->getOperation('foo')); $op->setClient(new Client()); $request = $op->prepare(); $response = new Response(200, array('Content-Type' => 'application/xml'), '<Foo><Baz>Bar</Baz></Foo>'); $request->setResponse($response, true); $this->assertSame($response, $op->execute()); }
public function testSkipsUnkownModels() { $parser = new OperationResponseParser(); $operation = $this->getDescription()->getOperation('test'); $operation->setResponseClass('Baz')->setResponseType('model'); $op = new OperationCommand(array(), $operation); $op->setResponseParser($parser)->setClient(new Client()); $op->prepare()->setResponse(new Response(201), true); $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $op->execute()); }
public function testDoesNotParseXmlWhenNotUsingXmlVisitor() { $parser = OperationResponseParser::getInstance(); $description = ServiceDescription::factory(array('operations' => array('test' => array('responseClass' => 'Foo')), 'models' => array('Foo' => array('type' => 'object', 'properties' => array('baz' => array('location' => 'body')))))); $operation = $description->getOperation('test'); $op = new OperationCommand(array(), $operation); $op->setResponseParser($parser)->setClient(new Client()); $brokenXml = '<broken><><><<xml>>>>>'; $op->prepare()->setResponse(new Response(200, array('Content-Type' => 'application/xml'), $brokenXml), true); $result = $op->execute(); $this->assertEquals(array('baz'), $result->getKeys()); $this->assertEquals($brokenXml, (string) $result['baz']); }
/** * @group issue-399 * @link https://github.com/guzzle/guzzle/issues/501 */ public function testAdditionalPropertiesWithRefAreResolved() { $parser = OperationResponseParser::getInstance(); $description = ServiceDescription::factory(array('operations' => array('test' => array('responseClass' => 'Foo')), 'models' => array('Baz' => array('type' => 'string'), 'Foo' => array('type' => 'object', 'additionalProperties' => array('$ref' => 'Baz', 'location' => 'json'))))); $operation = $description->getOperation('test'); $op = new OperationCommand(array(), $operation); $op->setResponseParser($parser)->setClient(new Client()); $json = '{"a":"a","b":"b","c":"c"}'; $op->prepare()->setResponse(new Response(200, array('Content-Type' => 'application/json'), $json), true); $result = $op->execute()->toArray(); $this->assertEquals(array('a' => 'a', 'b' => 'b', 'c' => 'c'), $result); }
/** * @expectedException \Guzzle\Service\Exception\ResponseClassException * @expectedExceptionMessage and implement */ public function testEnsuresResponseClassImplementsResponseClassInterface() { $parser = OperationResponseParser::getInstance(); $description = ServiceDescription::factory(array('operations' => array('test' => array('responseClass' => __CLASS__)))); $operation = $description->getOperation('test'); $op = new OperationCommand(array(), $operation); $op->setResponseParser($parser)->setClient(new Client()); $op->prepare()->setResponse(new Response(200, array('Content-Type' => 'application/json'), 'hi!'), true); $op->execute(); }