本文整理汇总了PHP中Guzzle\Service\Command\OperationCommand::setResponseParser方法的典型用法代码示例。如果您正苦于以下问题:PHP OperationCommand::setResponseParser方法的具体用法?PHP OperationCommand::setResponseParser怎么用?PHP OperationCommand::setResponseParser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Service\Command\OperationCommand
的用法示例。
在下文中一共展示了OperationCommand::setResponseParser方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testSkipsUnkownModels
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());
}
示例2: testParsesResponsesWithResponseParser
public function testParsesResponsesWithResponseParser()
{
$op = new OperationCommand(array(), new Operation());
$p = $this->getMockBuilder('Guzzle\\Service\\Command\\ResponseParserInterface')->setMethods(array('parse'))->getMockForAbstractClass();
$p->expects($this->once())->method('parse')->will($this->returnValue(array('foo' => 'bar')));
$op->setResponseParser($p);
$op->setClient(new Client());
$request = $op->prepare();
$request->setResponse(new Response(200), true);
$this->assertEquals(array('foo' => 'bar'), $op->execute());
}
示例3: testDoesNotParseXmlWhenNotUsingXmlVisitor
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']);
}
示例4: testAdditionalPropertiesWithRefAreResolved
/**
* @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);
}
示例5: testEnsuresResponseClassImplementsResponseClassInterface
/**
* @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();
}