public function testVisitsLocations()
 {
     $parser = new OperationResponseParser();
     $parser->addVisitor('statusCode', new StatusCodeVisitor());
     $parser->addVisitor('reasonPhrase', new ReasonPhraseVisitor());
     $op = new OperationCommand(array(), $this->getDescription()->getOperation('test'));
     $op->setResponseParser($parser)->setClient(new Client());
     $op->prepare()->setResponse(new Response(201), true);
     $result = $op->execute();
     $this->assertEquals(201, $result['code']);
     $this->assertEquals('Created', $result['phrase']);
 }
Esempio n. 2
0
 /**
  * {@inheritdoc}
  */
 protected function build()
 {
     // Prepare and serialize the request
     $this->request = $this->getRequestSerializer()->prepare($this);
     // If no response parser is set, add the default parser if a model matching the responseClass is found
     if (!$this->responseParser) {
         $this->responseParser = $this->operation->getResponseType() == OperationInterface::TYPE_MODEL && $this->get(self::RESPONSE_PROCESSING) == self::TYPE_MODEL ? OperationResponseParser::getInstance() : DefaultResponseParser::getInstance();
     }
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 protected function handleParsing(AbstractCommand $command, Response $response, $contentType)
 {
     // Only use overridden behaviour if response type is a model
     if (!$this->responseTypeIsModel($command)) {
         return parent::handleParsing($command, $response, $contentType);
     }
     // Preparation of model data (this is same as parent class)
     $structure = $command->getOperation()->getServiceDescription()->getModel($command->getOperation()->getResponseClass());
     $data = $this->visitResult($structure, $command, $response);
     return $this->createClass(static::MODEL_CLASS, array($data, $structure));
 }
 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']);
 }
Esempio n. 5
0
 /**
  * {@inheritdoc}
  */
 protected function build()
 {
     // By default, JSON commands with AWS require no response model processing
     if ($this->operation->getResponseType() == OperationInterface::TYPE_MODEL && $this->get(self::RESPONSE_PROCESSING) == self::TYPE_MODEL) {
         $this->responseParser = $this->get('command.model_processing') ? OperationResponseParser::getInstance() : NoTranslationOperationResponseParser::getInstance();
     } else {
         $this->responseParser = DefaultResponseParser::getInstance();
     }
     parent::build();
     // Ensure that the body of the request ALWAYS includes some JSON. By default, this is an empty object.
     if (!$this->request->getBody()) {
         $this->request->setBody('{}');
     }
     // Never send the Expect header when interacting with a JSON query service
     $this->request->removeHeader('Expect');
 }
 /**
  * @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();
 }