示例#1
0
 public function testAddsJsonHeader()
 {
     $visitor = new Visitor();
     $visitor->setContentTypeHeader('application/json-foo');
     $param = $this->getNestedCommand('json')->getParam('foo');
     $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
     $visitor->after($this->command, $this->request);
     $this->assertEquals('application/json-foo', (string) $this->request->getHeader('Content-Type'));
 }
示例#2
0
 /**
  * @covers Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor
  * @covers Guzzle\Service\Command\LocationVisitor\Request\AbstractRequestVisitor::resolveRecursively
  */
 public function testRecursivelyBuildsJsonBodies()
 {
     $command = $this->getCommand('json');
     $request = $command->prepare();
     $visitor = new Visitor();
     $param = $this->getNestedCommand('json')->getParam('foo');
     $visitor->visit($command, $request, $param->setSentAs('Foo'), $command['foo']);
     $visitor->after($command, $request);
     $this->assertEquals('{"Foo":{"test":{"baz":true,"Jenga_Yall!":"HELLO"},"bar":123}}', (string) $request->getBody());
 }
示例#3
0
 public function after(CommandInterface $command, RequestInterface $request)
 {
     if (isset($this->data[$command]) && is_array($this->data[$command])) {
         $json = $this->data[$command];
         array_walk_recursive($json, array(__CLASS__, 'sanitize'));
         $this->data[$command] = $json;
     }
     parent::after($command, $request);
 }