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')); }
/** * @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()); }
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); }