Open Monograph Press  3.3.0
Request/JsonVisitorTest.php
1 <?php
2 
4 
6 
12 {
13  public function testVisitsLocation()
14  {
15  $visitor = new Visitor();
16  // Test after when no body query values were found
17  $visitor->after($this->command, $this->request);
18 
19  $param = $this->getNestedCommand('json')->getParam('foo');
20  $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
21  $visitor->visit($this->command, $this->request, $param->setSentAs('test2'), 'abc');
22  $visitor->after($this->command, $this->request);
23  $this->assertEquals('{"test":"123","test2":"abc"}', (string) $this->request->getBody());
24  }
25 
26  public function testAddsJsonHeader()
27  {
28  $visitor = new Visitor();
29  $visitor->setContentTypeHeader('application/json-foo');
30  $param = $this->getNestedCommand('json')->getParam('foo');
31  $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
32  $visitor->after($this->command, $this->request);
33  $this->assertEquals('application/json-foo', (string) $this->request->getHeader('Content-Type'));
34  }
35 
37  {
38  $command = $this->getCommand('json');
39  $request = $command->prepare();
40  $this->assertEquals('{"Foo":{"test":{"baz":true,"Jenga_Yall!":"HELLO"},"bar":123}}', (string) $request->getBody());
41  }
42 
44  {
45  $command = $this->getCommand('json');
46  $command->set('foo', array('not_set' => 'abc'));
47  $request = $command->prepare();
48  $result = json_decode($request->getBody(), true);
49  $this->assertEquals('ABC', $result['Foo']['not_set']);
50  }
51 
53  {
54  $command = $this->getCommand('json');
55  $command->set('arr', array('a', 'b'));
56  $request = $command->prepare();
57  $result = json_decode($request->getBody(), true);
58  $this->assertEquals(array('A', 'B'), $result['arr']);
59  }
60 }
Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor
Definition: Request/JsonVisitor.php:12
Guzzle\Tests\Service\Command\LocationVisitor\Request\JsonVisitorTest\testVisitsLocation
testVisitsLocation()
Definition: Request/JsonVisitorTest.php:13
Guzzle\Tests\Service\Command\LocationVisitor\Request\JsonVisitorTest
Definition: Request/JsonVisitorTest.php:11
Guzzle\Tests\Service\Command\LocationVisitor\Request
Definition: AbstractVisitorTestCase.php:3
Guzzle\Tests\Service\Command\LocationVisitor\Request\AbstractVisitorTestCase\$param
$param
Definition: AbstractVisitorTestCase.php:17
Guzzle\Tests\Service\Command\LocationVisitor\Request\JsonVisitorTest\testAddsJsonHeader
testAddsJsonHeader()
Definition: Request/JsonVisitorTest.php:26
Guzzle\Tests\Service\Command\LocationVisitor\Request\AbstractVisitorTestCase\getCommand
getCommand($location)
Definition: AbstractVisitorTestCase.php:27
Guzzle\Tests\Service\Command\LocationVisitor\Request\AbstractVisitorTestCase\getNestedCommand
getNestedCommand($location)
Definition: AbstractVisitorTestCase.php:35
Guzzle\Tests\Service\Command\LocationVisitor\Request\AbstractVisitorTestCase\$command
$command
Definition: AbstractVisitorTestCase.php:15
Guzzle\Tests\Service\Command\LocationVisitor\Request\JsonVisitorTest\testAppliesFiltersToAdditionalProperties
testAppliesFiltersToAdditionalProperties()
Definition: Request/JsonVisitorTest.php:43
Guzzle\Tests\Service\Command\LocationVisitor\Request\AbstractVisitorTestCase
Definition: AbstractVisitorTestCase.php:13
Guzzle\Tests\Service\Command\LocationVisitor\Request\JsonVisitorTest\testRecursivelyBuildsJsonBodies
testRecursivelyBuildsJsonBodies()
Definition: Request/JsonVisitorTest.php:36
Guzzle\Tests\Service\Command\LocationVisitor\Request\JsonVisitorTest\testAppliesFiltersToArrayItemValues
testAppliesFiltersToArrayItemValues()
Definition: Request/JsonVisitorTest.php:52
Guzzle\Tests\Service\Command\LocationVisitor\Request\AbstractVisitorTestCase\$request
$request
Definition: AbstractVisitorTestCase.php:16