summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor')
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/AbstractVisitorTestCase.php110
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/BodyVisitorTest.php63
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/HeaderVisitorTest.php48
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/JsonVisitorTest.php60
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFieldVisitorTest.php33
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFileVisitorTest.php54
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/QueryVisitorTest.php48
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/ResponseBodyVisitorTest.php20
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/XmlVisitorTest.php558
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/AbstractResponseVisitorTest.php29
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/BodyVisitorTest.php21
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/HeaderVisitorTest.php98
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/JsonVisitorTest.php157
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/ReasonPhraseVisitorTest.php21
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/StatusCodeVisitorTest.php21
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/XmlVisitorTest.php431
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/VisitorFlyweightTest.php53
17 files changed, 1825 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/AbstractVisitorTestCase.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/AbstractVisitorTestCase.php
new file mode 100644
index 0000000..46b472e
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/AbstractVisitorTestCase.php
@@ -0,0 +1,110 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\Message\EntityEnclosingRequest;
+use Guzzle\Service\Description\Operation;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Description\SchemaValidator;
+use Guzzle\Service\Command\OperationCommand;
+use Guzzle\Tests\Service\Mock\Command\MockCommand;
+use Guzzle\Tests\Service\Mock\MockClient;
+
+abstract class AbstractVisitorTestCase extends \Guzzle\Tests\GuzzleTestCase
+{
+ protected $command;
+ protected $request;
+ protected $param;
+ protected $validator;
+
+ public function setUp()
+ {
+ $this->command = new MockCommand();
+ $this->request = new EntityEnclosingRequest('POST', 'http://www.test.com/some/path.php');
+ $this->validator = new SchemaValidator();
+ }
+
+ protected function getCommand($location)
+ {
+ $command = new OperationCommand(array(), $this->getNestedCommand($location));
+ $command->setClient(new MockClient());
+
+ return $command;
+ }
+
+ protected function getNestedCommand($location)
+ {
+ return new Operation(array(
+ 'httpMethod' => 'POST',
+ 'parameters' => array(
+ 'foo' => new Parameter(array(
+ 'type' => 'object',
+ 'location' => $location,
+ 'sentAs' => 'Foo',
+ 'required' => true,
+ 'properties' => array(
+ 'test' => array(
+ 'type' => 'object',
+ 'required' => true,
+ 'properties' => array(
+ 'baz' => array(
+ 'type' => 'boolean',
+ 'default' => true
+ ),
+ 'jenga' => array(
+ 'type' => 'string',
+ 'default' => 'hello',
+ 'sentAs' => 'Jenga_Yall!',
+ 'filters' => array('strtoupper')
+ )
+ )
+ ),
+ 'bar' => array('default' => 123)
+ ),
+ 'additionalProperties' => array(
+ 'type' => 'string',
+ 'filters' => array('strtoupper'),
+ 'location' => $location
+ )
+ )),
+ 'arr' => new Parameter(array(
+ 'type' => 'array',
+ 'location' => $location,
+ 'items' => array(
+ 'type' => 'string',
+ 'filters' => array('strtoupper')
+ )
+ )),
+ )
+ ));
+ }
+
+ protected function getCommandWithArrayParamAndFilters()
+ {
+ $operation = new Operation(array(
+ 'httpMethod' => 'POST',
+ 'parameters' => array(
+ 'foo' => new Parameter(array(
+ 'type' => 'string',
+ 'location' => 'query',
+ 'sentAs' => 'Foo',
+ 'required' => true,
+ 'default' => 'bar',
+ 'filters' => array('strtoupper')
+ )),
+ 'arr' => new Parameter(array(
+ 'type' => 'array',
+ 'location' => 'query',
+ 'sentAs' => 'Arr',
+ 'required' => true,
+ 'default' => array(123, 456, 789),
+ 'filters' => array(array('method' => 'implode', 'args' => array(',', '@value')))
+ ))
+ )
+ ));
+ $command = new OperationCommand(array(), $operation);
+ $command->setClient(new MockClient());
+
+ return $command;
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/BodyVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/BodyVisitorTest.php
new file mode 100644
index 0000000..2a95c45
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/BodyVisitorTest.php
@@ -0,0 +1,63 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Http\EntityBody;
+use Guzzle\Service\Command\LocationVisitor\Request\BodyVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\BodyVisitor
+ */
+class BodyVisitorTest extends AbstractVisitorTestCase
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
+ $visitor->visit($this->command, $this->request, $param, '123');
+ $this->assertEquals('123', (string) $this->request->getBody());
+ $this->assertNull($this->request->getHeader('Expect'));
+ }
+
+ public function testAddsExpectHeaderWhenSetToTrue()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
+ $param->setData('expect_header', true);
+ $visitor->visit($this->command, $this->request, $param, '123');
+ $this->assertEquals('123', (string) $this->request->getBody());
+ }
+
+ public function testCanDisableExpectHeader()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
+ $param->setData('expect_header', false);
+ $visitor->visit($this->command, $this->request, $param, '123');
+ $this->assertNull($this->request->getHeader('Expect'));
+ }
+
+ public function testCanSetExpectHeaderBasedOnSize()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
+ // The body is less than the cutoff
+ $param->setData('expect_header', 5);
+ $visitor->visit($this->command, $this->request, $param, '123');
+ $this->assertNull($this->request->getHeader('Expect'));
+ // Now check when the body is greater than the cutoff
+ $param->setData('expect_header', 2);
+ $visitor->visit($this->command, $this->request, $param, '123');
+ $this->assertEquals('100-Continue', (string) $this->request->getHeader('Expect'));
+ }
+
+ public function testAddsContentEncodingWhenSetOnBody()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
+ $body = EntityBody::factory('foo');
+ $body->compress();
+ $visitor->visit($this->command, $this->request, $param, $body);
+ $this->assertEquals('gzip', (string) $this->request->getHeader('Content-Encoding'));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/HeaderVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/HeaderVisitorTest.php
new file mode 100644
index 0000000..7ea1ae9
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/HeaderVisitorTest.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Command\LocationVisitor\Request\HeaderVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\HeaderVisitor
+ */
+class HeaderVisitorTest extends AbstractVisitorTestCase
+{
+ /**
+ * @expectedException \Guzzle\Common\Exception\InvalidArgumentException
+ */
+ public function testValidatesHeaderMapsAreArrays()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('header')->getParam('foo')->setSentAs('test');
+ $param->setAdditionalProperties(new Parameter(array()));
+ $visitor->visit($this->command, $this->request, $param, 'test');
+ }
+
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('header')->getParam('foo')->setSentAs('test');
+ $param->setAdditionalProperties(false);
+ $visitor->visit($this->command, $this->request, $param, '123');
+ $this->assertEquals('123', (string) $this->request->getHeader('test'));
+ }
+
+ public function testVisitsMappedPrefixHeaders()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('header')->getParam('foo')->setSentAs('test');
+ $param->setSentAs('x-foo-');
+ $param->setAdditionalProperties(new Parameter(array(
+ 'type' => 'string'
+ )));
+ $visitor->visit($this->command, $this->request, $param, array(
+ 'bar' => 'test',
+ 'baz' => '123'
+ ));
+ $this->assertEquals('test', (string) $this->request->getHeader('x-foo-bar'));
+ $this->assertEquals('123', (string) $this->request->getHeader('x-foo-baz'));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/JsonVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/JsonVisitorTest.php
new file mode 100644
index 0000000..ea6782f
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/JsonVisitorTest.php
@@ -0,0 +1,60 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\AbstractRequestVisitor::resolveRecursively
+ */
+class JsonVisitorTest extends AbstractVisitorTestCase
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ // Test after when no body query values were found
+ $visitor->after($this->command, $this->request);
+
+ $param = $this->getNestedCommand('json')->getParam('foo');
+ $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
+ $visitor->visit($this->command, $this->request, $param->setSentAs('test2'), 'abc');
+ $visitor->after($this->command, $this->request);
+ $this->assertEquals('{"test":"123","test2":"abc"}', (string) $this->request->getBody());
+ }
+
+ 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'));
+ }
+
+ public function testRecursivelyBuildsJsonBodies()
+ {
+ $command = $this->getCommand('json');
+ $request = $command->prepare();
+ $this->assertEquals('{"Foo":{"test":{"baz":true,"Jenga_Yall!":"HELLO"},"bar":123}}', (string) $request->getBody());
+ }
+
+ public function testAppliesFiltersToAdditionalProperties()
+ {
+ $command = $this->getCommand('json');
+ $command->set('foo', array('not_set' => 'abc'));
+ $request = $command->prepare();
+ $result = json_decode($request->getBody(), true);
+ $this->assertEquals('ABC', $result['Foo']['not_set']);
+ }
+
+ public function testAppliesFiltersToArrayItemValues()
+ {
+ $command = $this->getCommand('json');
+ $command->set('arr', array('a', 'b'));
+ $request = $command->prepare();
+ $result = json_decode($request->getBody(), true);
+ $this->assertEquals(array('A', 'B'), $result['arr']);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFieldVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFieldVisitorTest.php
new file mode 100644
index 0000000..540b410
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFieldVisitorTest.php
@@ -0,0 +1,33 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Command\LocationVisitor\Request\PostFieldVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\PostFieldVisitor
+ */
+class PostFieldVisitorTest extends AbstractVisitorTestCase
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('postField')->getParam('foo');
+ $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
+ $this->assertEquals('123', (string) $this->request->getPostField('test'));
+ }
+
+ public function testRecursivelyBuildsPostFields()
+ {
+ $command = $this->getCommand('postField');
+ $request = $command->prepare();
+ $visitor = new Visitor();
+ $param = $command->getOperation()->getParam('foo');
+ $visitor->visit($command, $request, $param, $command['foo']);
+ $visitor->after($command, $request);
+ $this->assertEquals(
+ 'Foo[test][baz]=1&Foo[test][Jenga_Yall!]=HELLO&Foo[bar]=123',
+ rawurldecode((string) $request->getPostFields())
+ );
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFileVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFileVisitorTest.php
new file mode 100644
index 0000000..21e3cec
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/PostFileVisitorTest.php
@@ -0,0 +1,54 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Client;
+use Guzzle\Service\Description\ServiceDescription;
+use Guzzle\Http\Message\PostFile;
+use Guzzle\Service\Command\LocationVisitor\Request\PostFileVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\PostFileVisitor
+ */
+class PostFileVisitorTest extends AbstractVisitorTestCase
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('postFile')->getParam('foo');
+
+ // Test using a path to a file
+ $visitor->visit($this->command, $this->request, $param->setSentAs('test_3'), __FILE__);
+ $this->assertInternalType('array', $this->request->getPostFile('test_3'));
+
+ // Test with a PostFile
+ $visitor->visit($this->command, $this->request, $param->setSentAs(null), new PostFile('baz', __FILE__));
+ $this->assertInternalType('array', $this->request->getPostFile('baz'));
+ }
+
+ public function testVisitsLocationWithMultipleFiles()
+ {
+ $description = ServiceDescription::factory(array(
+ 'operations' => array(
+ 'DoPost' => array(
+ 'httpMethod' => 'POST',
+ 'parameters' => array(
+ 'foo' => array(
+ 'location' => 'postFile',
+ 'type' => array('string', 'array')
+ )
+ )
+ )
+ )
+ ));
+ $this->getServer()->flush();
+ $this->getServer()->enqueue(array("HTTP/1.1 200 OK\r\nContent-Length:0\r\n\r\n"));
+ $client = new Client($this->getServer()->getUrl());
+ $client->setDescription($description);
+ $command = $client->getCommand('DoPost', array('foo' => array(__FILE__, __FILE__)));
+ $command->execute();
+ $received = $this->getServer()->getReceivedRequests();
+ $this->assertContains('name="foo[0]";', $received[0]);
+ $this->assertContains('name="foo[1]";', $received[0]);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/QueryVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/QueryVisitorTest.php
new file mode 100644
index 0000000..607af76
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/QueryVisitorTest.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Command\LocationVisitor\Request\QueryVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\QueryVisitor
+ */
+class QueryVisitorTest extends AbstractVisitorTestCase
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('query')->getParam('foo')->setSentAs('test');
+ $visitor->visit($this->command, $this->request, $param, '123');
+ $this->assertEquals('123', $this->request->getQuery()->get('test'));
+ }
+
+ /**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\QueryVisitor
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\AbstractRequestVisitor::resolveRecursively
+ */
+ public function testRecursivelyBuildsQueryStrings()
+ {
+ $command = $this->getCommand('query');
+ $command->getOperation()->getParam('foo')->setSentAs('Foo');
+ $request = $command->prepare();
+ $this->assertEquals(
+ 'Foo[test][baz]=1&Foo[test][Jenga_Yall!]=HELLO&Foo[bar]=123',
+ rawurldecode($request->getQuery())
+ );
+ }
+
+ /**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\AbstractRequestVisitor::resolveRecursively
+ */
+ public function testFiltersAreAppliedToArrayParamType()
+ {
+ $command = $this->getCommandWithArrayParamAndFilters();
+ $request = $command->prepare();
+ $query = $request->getQuery();
+ // param type 'string'
+ $this->assertEquals('BAR', $query->get('Foo'));
+ // param type 'array'
+ $this->assertEquals('123,456,789', $query->get('Arr'));
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/ResponseBodyVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/ResponseBodyVisitorTest.php
new file mode 100644
index 0000000..ff8cec5
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/ResponseBodyVisitorTest.php
@@ -0,0 +1,20 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Command\LocationVisitor\Request\ResponseBodyVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\ResponseBodyVisitor
+ */
+class ResponseBodyVisitorTest extends AbstractVisitorTestCase
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = $this->getNestedCommand('response_body')->getParam('foo');
+ $visitor->visit($this->command, $this->request, $param, sys_get_temp_dir() . '/foo.txt');
+ $body = $this->readAttribute($this->request, 'responseBody');
+ $this->assertContains('/foo.txt', $body->getUri());
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/XmlVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/XmlVisitorTest.php
new file mode 100644
index 0000000..beb58b0
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Request/XmlVisitorTest.php
@@ -0,0 +1,558 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Request;
+
+use Guzzle\Service\Command\LocationVisitor\Request\XmlVisitor;
+use Guzzle\Service\Client;
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Service\Description\Operation;
+use Guzzle\Http\Message\EntityEnclosingRequest;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Request\XmlVisitor
+ */
+class XmlVisitorTest extends AbstractVisitorTestCase
+{
+ public function xmlProvider()
+ {
+ return array(
+ array(
+ array(
+ 'data' => array(
+ 'xmlRoot' => array(
+ 'name' => 'test',
+ 'namespaces' => 'http://foo.com'
+ )
+ ),
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string'),
+ 'Baz' => array('location' => 'xml', 'type' => 'string')
+ )
+ ),
+ array('Foo' => 'test', 'Baz' => 'bar'),
+ '<test xmlns="http://foo.com"><Foo>test</Foo><Baz>bar</Baz></test>'
+ ),
+ // Ensure that the content-type is not added
+ array(array('parameters' => array('Foo' => array('location' => 'xml', 'type' => 'string'))), array(), ''),
+ // Test with adding attributes and no namespace
+ array(
+ array(
+ 'data' => array(
+ 'xmlRoot' => array(
+ 'name' => 'test'
+ )
+ ),
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string', 'data' => array('xmlAttribute' => true))
+ )
+ ),
+ array('Foo' => 'test', 'Baz' => 'bar'),
+ '<test Foo="test"/>'
+ ),
+ // Test adding with an array
+ array(
+ array(
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string'),
+ 'Baz' => array(
+ 'type' => 'array',
+ 'location' => 'xml',
+ 'items' => array(
+ 'type' => 'numeric',
+ 'sentAs' => 'Bar'
+ )
+ )
+ )
+ ),
+ array('Foo' => 'test', 'Baz' => array(1, 2)),
+ '<Request><Foo>test</Foo><Baz><Bar>1</Bar><Bar>2</Bar></Baz></Request>'
+ ),
+ // Test adding an object
+ array(
+ array(
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string'),
+ 'Baz' => array(
+ 'type' => 'object',
+ 'location' => 'xml',
+ 'properties' => array(
+ 'Bar' => array('type' => 'string'),
+ 'Bam' => array()
+ )
+ )
+ )
+ ),
+ array('Foo' => 'test', 'Baz' => array('Bar' => 'abc', 'Bam' => 'foo')),
+ '<Request><Foo>test</Foo><Baz><Bar>abc</Bar><Bam>foo</Bam></Baz></Request>'
+ ),
+ // Add an array that contains an object
+ array(
+ array(
+ 'parameters' => array(
+ 'Baz' => array(
+ 'type' => 'array',
+ 'location' => 'xml',
+ 'items' => array(
+ 'type' => 'object',
+ 'sentAs' => 'Bar',
+ 'properties' => array('A' => array(), 'B' => array())
+ )
+ )
+ )
+ ),
+ array('Baz' => array(
+ array('A' => '1', 'B' => '2'),
+ array('A' => '3', 'B' => '4')
+ )),
+ '<Request><Baz><Bar><A>1</A><B>2</B></Bar><Bar><A>3</A><B>4</B></Bar></Baz></Request>'
+ ),
+ // Add an object of attributes
+ array(
+ array(
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string'),
+ 'Baz' => array(
+ 'type' => 'object',
+ 'location' => 'xml',
+ 'properties' => array(
+ 'Bar' => array('type' => 'string', 'data' => array('xmlAttribute' => true)),
+ 'Bam' => array()
+ )
+ )
+ )
+ ),
+ array('Foo' => 'test', 'Baz' => array('Bar' => 'abc', 'Bam' => 'foo')),
+ '<Request><Foo>test</Foo><Baz Bar="abc"><Bam>foo</Bam></Baz></Request>'
+ ),
+ // Check order doesn't matter
+ array(
+ array(
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string'),
+ 'Baz' => array(
+ 'type' => 'object',
+ 'location' => 'xml',
+ 'properties' => array(
+ 'Bar' => array('type' => 'string', 'data' => array('xmlAttribute' => true)),
+ 'Bam' => array()
+ )
+ )
+ )
+ ),
+ array('Foo' => 'test', 'Baz' => array('Bam' => 'foo', 'Bar' => 'abc')),
+ '<Request><Foo>test</Foo><Baz Bar="abc"><Bam>foo</Bam></Baz></Request>'
+ ),
+ // Add values with custom namespaces
+ array(
+ array(
+ 'parameters' => array(
+ 'Foo' => array(
+ 'location' => 'xml',
+ 'type' => 'string',
+ 'data' => array(
+ 'xmlNamespace' => 'http://foo.com'
+ )
+ )
+ )
+ ),
+ array('Foo' => 'test'),
+ '<Request><Foo xmlns="http://foo.com">test</Foo></Request>'
+ ),
+ // Add attributes with custom namespace prefix
+ array(
+ array(
+ 'parameters' => array(
+ 'Wrap' => array(
+ 'type' => 'object',
+ 'location' => 'xml',
+ 'properties' => array(
+ 'Foo' => array(
+ 'type' => 'string',
+ 'sentAs' => 'xsi:baz',
+ 'data' => array(
+ 'xmlNamespace' => 'http://foo.com',
+ 'xmlAttribute' => true
+ )
+ )
+ )
+ ),
+ )
+ ),
+ array('Wrap' => array(
+ 'Foo' => 'test'
+ )),
+ '<Request><Wrap xsi:baz="test" xmlns:xsi="http://foo.com"/></Request>'
+ ),
+ // Add nodes with custom namespace prefix
+ array(
+ array(
+ 'parameters' => array(
+ 'Wrap' => array(
+ 'type' => 'object',
+ 'location' => 'xml',
+ 'properties' => array(
+ 'Foo' => array(
+ 'type' => 'string',
+ 'sentAs' => 'xsi:Foo',
+ 'data' => array(
+ 'xmlNamespace' => 'http://foobar.com'
+ )
+ )
+ )
+ ),
+ )
+ ),
+ array('Wrap' => array(
+ 'Foo' => 'test'
+ )),
+ '<Request><Wrap><xsi:Foo xmlns:xsi="http://foobar.com">test</xsi:Foo></Wrap></Request>'
+ ),
+ array(
+ array(
+ 'parameters' => array(
+ 'Foo' => array(
+ 'location' => 'xml',
+ 'type' => 'string',
+ 'data' => array(
+ 'xmlNamespace' => 'http://foo.com'
+ )
+ )
+ )
+ ),
+ array('Foo' => '<h1>This is a title</h1>'),
+ '<Request><Foo xmlns="http://foo.com"><![CDATA[<h1>This is a title</h1>]]></Foo></Request>'
+ ),
+ // Flat array at top level
+ array(
+ array(
+ 'parameters' => array(
+ 'Bars' => array(
+ 'type' => 'array',
+ 'data' => array('xmlFlattened' => true),
+ 'location' => 'xml',
+ 'items' => array(
+ 'type' => 'object',
+ 'sentAs' => 'Bar',
+ 'properties' => array(
+ 'A' => array(),
+ 'B' => array()
+ )
+ )
+ ),
+ 'Boos' => array(
+ 'type' => 'array',
+ 'data' => array('xmlFlattened' => true),
+ 'location' => 'xml',
+ 'items' => array(
+ 'sentAs' => 'Boo',
+ 'type' => 'string'
+ )
+ )
+ )
+ ),
+ array(
+ 'Bars' => array(
+ array('A' => '1', 'B' => '2'),
+ array('A' => '3', 'B' => '4')
+ ),
+ 'Boos' => array('test', '123')
+ ),
+ '<Request><Bar><A>1</A><B>2</B></Bar><Bar><A>3</A><B>4</B></Bar><Boo>test</Boo><Boo>123</Boo></Request>'
+ ),
+ // Nested flat arrays
+ array(
+ array(
+ 'parameters' => array(
+ 'Delete' => array(
+ 'type' => 'object',
+ 'location' => 'xml',
+ 'properties' => array(
+ 'Items' => array(
+ 'type' => 'array',
+ 'data' => array('xmlFlattened' => true),
+ 'items' => array(
+ 'type' => 'object',
+ 'sentAs' => 'Item',
+ 'properties' => array(
+ 'A' => array(),
+ 'B' => array()
+ )
+ )
+ )
+ )
+ )
+ )
+ ),
+ array(
+ 'Delete' => array(
+ 'Items' => array(
+ array('A' => '1', 'B' => '2'),
+ array('A' => '3', 'B' => '4')
+ )
+ )
+ ),
+ '<Request><Delete><Item><A>1</A><B>2</B></Item><Item><A>3</A><B>4</B></Item></Delete></Request>'
+ )
+ );
+ }
+
+ /**
+ * @dataProvider xmlProvider
+ */
+ public function testSerializesXml(array $operation, array $input, $xml)
+ {
+ $operation = new Operation($operation);
+ $command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
+ ->setConstructorArgs(array($input, $operation))
+ ->getMockForAbstractClass();
+ $command->setClient(new Client('http://www.test.com/some/path.php'));
+ $request = $command->prepare();
+ if (!empty($input)) {
+ $this->assertEquals('application/xml', (string) $request->getHeader('Content-Type'));
+ } else {
+ $this->assertNull($request->getHeader('Content-Type'));
+ }
+ $body = str_replace(array("\n", "<?xml version=\"1.0\"?>"), '', (string) $request->getBody());
+ $this->assertEquals($xml, $body);
+ }
+
+ public function testAddsContentTypeAndTopLevelValues()
+ {
+ $operation = new Operation(array(
+ 'data' => array(
+ 'xmlRoot' => array(
+ 'name' => 'test',
+ 'namespaces' => array(
+ 'xsi' => 'http://foo.com'
+ )
+ )
+ ),
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string'),
+ 'Baz' => array('location' => 'xml', 'type' => 'string')
+ )
+ ));
+
+ $command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
+ ->setConstructorArgs(array(array(
+ 'Foo' => 'test',
+ 'Baz' => 'bar'
+ ), $operation))
+ ->getMockForAbstractClass();
+
+ $command->setClient(new Client());
+ $request = $command->prepare();
+ $this->assertEquals('application/xml', (string) $request->getHeader('Content-Type'));
+ $this->assertEquals(
+ '<?xml version="1.0"?>' . "\n"
+ . '<test xmlns:xsi="http://foo.com"><Foo>test</Foo><Baz>bar</Baz></test>' . "\n",
+ (string) $request->getBody()
+ );
+ }
+
+ public function testCanChangeContentType()
+ {
+ $visitor = new XmlVisitor();
+ $visitor->setContentTypeHeader('application/foo');
+ $this->assertEquals('application/foo', $this->readAttribute($visitor, 'contentType'));
+ }
+
+ public function testCanAddArrayOfSimpleTypes()
+ {
+ $request = new EntityEnclosingRequest('POST', 'http://foo.com');
+ $visitor = new XmlVisitor();
+ $param = new Parameter(array(
+ 'type' => 'object',
+ 'location' => 'xml',
+ 'name' => 'Out',
+ 'properties' => array(
+ 'Nodes' => array(
+ 'required' => true,
+ 'type' => 'array',
+ 'min' => 1,
+ 'items' => array('type' => 'string', 'sentAs' => 'Node')
+ )
+ )
+ ));
+
+ $param->setParent(new Operation(array(
+ 'data' => array(
+ 'xmlRoot' => array(
+ 'name' => 'Test',
+ 'namespaces' => array(
+ 'https://foo/'
+ )
+ )
+ )
+ )));
+
+ $value = array('Nodes' => array('foo', 'baz'));
+ $this->assertTrue($this->validator->validate($param, $value));
+ $visitor->visit($this->command, $request, $param, $value);
+ $visitor->after($this->command, $request);
+
+ $this->assertEquals(
+ "<?xml version=\"1.0\"?>\n"
+ . "<Test xmlns=\"https://foo/\"><Out><Nodes><Node>foo</Node><Node>baz</Node></Nodes></Out></Test>\n",
+ (string) $request->getBody()
+ );
+ }
+
+ public function testCanAddMultipleNamespacesToRoot()
+ {
+ $operation = new Operation(array(
+ 'data' => array(
+ 'xmlRoot' => array(
+ 'name' => 'Hi',
+ 'namespaces' => array(
+ 'xsi' => 'http://foo.com',
+ 'foo' => 'http://foobar.com'
+ )
+ )
+ ),
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml', 'type' => 'string')
+ )
+ ));
+
+ $command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
+ ->setConstructorArgs(array(array(
+ 'Foo' => 'test'
+ ), $operation))
+ ->getMockForAbstractClass();
+
+ $command->setClient(new Client());
+ $request = $command->prepare();
+ $this->assertEquals('application/xml', (string) $request->getHeader('Content-Type'));
+ $this->assertEquals(
+ '<?xml version="1.0"?>' . "\n"
+ . '<Hi xmlns:xsi="http://foo.com" xmlns:foo="http://foobar.com"><Foo>test</Foo></Hi>' . "\n",
+ (string) $request->getBody()
+ );
+ }
+
+ public function testValuesAreFiltered()
+ {
+ $operation = new Operation(array(
+ 'parameters' => array(
+ 'Foo' => array(
+ 'location' => 'xml',
+ 'type' => 'string',
+ 'filters' => array('strtoupper')
+ ),
+ 'Bar' => array(
+ 'location' => 'xml',
+ 'type' => 'object',
+ 'properties' => array(
+ 'Baz' => array(
+ 'filters' => array('strtoupper')
+ )
+ )
+ )
+ )
+ ));
+
+ $command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
+ ->setConstructorArgs(array(array(
+ 'Foo' => 'test',
+ 'Bar' => array(
+ 'Baz' => 'abc'
+ )
+ ), $operation))
+ ->getMockForAbstractClass();
+
+ $command->setClient(new Client());
+ $request = $command->prepare();
+ $this->assertEquals(
+ '<?xml version="1.0"?>' . "\n"
+ . '<Request><Foo>TEST</Foo><Bar><Baz>ABC</Baz></Bar></Request>' . "\n",
+ (string) $request->getBody()
+ );
+ }
+
+ public function testSkipsNullValues()
+ {
+ $operation = new Operation(array(
+ 'parameters' => array(
+ 'Foo' => array(
+ 'location' => 'xml',
+ 'type' => 'string'
+ ),
+ 'Bar' => array(
+ 'location' => 'xml',
+ 'type' => 'object',
+ 'properties' => array(
+ 'Baz' => array(),
+ 'Bam' => array(),
+ )
+ ),
+ 'Arr' => array(
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'string'
+ )
+ )
+ )
+ ));
+
+ $command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
+ ->setConstructorArgs(array(array(
+ 'Foo' => null,
+ 'Bar' => array(
+ 'Bar' => null,
+ 'Bam' => 'test'
+ ),
+ 'Arr' => array(null)
+ ), $operation))
+ ->getMockForAbstractClass();
+
+ $command->setClient(new Client());
+ $request = $command->prepare();
+ $this->assertEquals(
+ '<?xml version="1.0"?>' . "\n"
+ . '<Request><Bar><Bam>test</Bam></Bar></Request>' . "\n",
+ (string) $request->getBody()
+ );
+ }
+
+ public function testAllowsXmlEncoding()
+ {
+ $operation = new Operation(array(
+ 'data' => array(
+ 'xmlEncoding' => 'UTF-8'
+ ),
+ 'parameters' => array(
+ 'Foo' => array('location' => 'xml')
+ )
+ ));
+ $command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
+ ->setConstructorArgs(array(array('Foo' => 'test'), $operation))
+ ->getMockForAbstractClass();
+ $command->setClient(new Client());
+ $request = $command->prepare();
+ $this->assertEquals(
+ '<?xml version="1.0" encoding="UTF-8"?>' . "\n"
+ . '<Request><Foo>test</Foo></Request>' . "\n",
+ (string) $request->getBody()
+ );
+ }
+
+ public function testAllowsSendingXmlPayloadIfNoXmlParamsWereSet()
+ {
+ $operation = new Operation(array(
+ 'httpMethod' => 'POST',
+ 'data' => array('xmlAllowEmpty' => true),
+ 'parameters' => array('Foo' => array('location' => 'xml'))
+ ));
+ $command = $this->getMockBuilder('Guzzle\Service\Command\OperationCommand')
+ ->setConstructorArgs(array(array(), $operation))
+ ->getMockForAbstractClass();
+ $command->setClient(new Client('http://foo.com'));
+ $request = $command->prepare();
+ $this->assertEquals(
+ '<?xml version="1.0"?>' . "\n"
+ . '<Request/>' . "\n",
+ (string) $request->getBody()
+ );
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/AbstractResponseVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/AbstractResponseVisitorTest.php
new file mode 100644
index 0000000..7b86003
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/AbstractResponseVisitorTest.php
@@ -0,0 +1,29 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Tests\Service\Mock\Command\MockCommand;
+use Guzzle\Http\Message\Response;
+
+abstract class AbstractResponseVisitorTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ /** @var Response */
+ protected $response;
+
+ /** @var MockCommand */
+ protected $command;
+
+ /** @var array */
+ protected $value;
+
+ public function setUp()
+ {
+ $this->value = array();
+ $this->command = new MockCommand();
+ $this->response = new Response(200, array(
+ 'X-Foo' => 'bar',
+ 'Content-Length' => 3,
+ 'Content-Type' => 'text/plain'
+ ), 'Foo');
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/BodyVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/BodyVisitorTest.php
new file mode 100644
index 0000000..932e39b
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/BodyVisitorTest.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Command\LocationVisitor\Response\BodyVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Response\BodyVisitor
+ */
+class BodyVisitorTest extends AbstractResponseVisitorTest
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array('location' => 'body', 'name' => 'foo'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals('Foo', (string) $this->value['foo']);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/HeaderVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/HeaderVisitorTest.php
new file mode 100644
index 0000000..db54b1a
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/HeaderVisitorTest.php
@@ -0,0 +1,98 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Command\LocationVisitor\Response\HeaderVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Response\HeaderVisitor
+ */
+class HeaderVisitorTest extends AbstractResponseVisitorTest
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'header',
+ 'name' => 'ContentType',
+ 'sentAs' => 'Content-Type'
+ ));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals('text/plain', $this->value['ContentType']);
+ }
+
+ public function testVisitsLocationWithFilters()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'header',
+ 'name' => 'Content-Type',
+ 'filters' => array('strtoupper')
+ ));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals('TEXT/PLAIN', $this->value['Content-Type']);
+ }
+
+ public function testVisitsMappedPrefixHeaders()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'header',
+ 'name' => 'Metadata',
+ 'sentAs' => 'X-Baz-',
+ 'type' => 'object',
+ 'additionalProperties' => array(
+ 'type' => 'string'
+ )
+ ));
+ $response = new Response(200, array(
+ 'X-Baz-Test' => 'ABC',
+ 'X-Baz-Bar' => array('123', '456'),
+ 'Content-Length' => 3
+ ), 'Foo');
+ $visitor->visit($this->command, $response, $param, $this->value);
+ $this->assertEquals(array(
+ 'Metadata' => array(
+ 'Test' => 'ABC',
+ 'Bar' => array('123', '456')
+ )
+ ), $this->value);
+ }
+
+ /**
+ * @group issue-399
+ * @link https://github.com/guzzle/guzzle/issues/399
+ */
+ public function testDiscardingUnknownHeaders()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'header',
+ 'name' => 'Content-Type',
+ 'additionalParameters' => false
+ ));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals('text/plain', $this->value['Content-Type']);
+ $this->assertArrayNotHasKey('X-Foo', $this->value);
+ }
+
+ /**
+ * @group issue-399
+ * @link https://github.com/guzzle/guzzle/issues/399
+ */
+ public function testDiscardingUnknownPropertiesWithAliasing()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'header',
+ 'name' => 'ContentType',
+ 'sentAs' => 'Content-Type',
+ 'additionalParameters' => false
+ ));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals('text/plain', $this->value['ContentType']);
+ $this->assertArrayNotHasKey('X-Foo', $this->value);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/JsonVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/JsonVisitorTest.php
new file mode 100644
index 0000000..4f8d30b
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/JsonVisitorTest.php
@@ -0,0 +1,157 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor
+ */
+class JsonVisitorTest extends AbstractResponseVisitorTest
+{
+ public function testBeforeMethodParsesXml()
+ {
+ $visitor = new Visitor();
+ $command = $this->getMockBuilder('Guzzle\Service\Command\AbstractCommand')
+ ->setMethods(array('getResponse'))
+ ->getMockForAbstractClass();
+ $command->expects($this->once())
+ ->method('getResponse')
+ ->will($this->returnValue(new Response(200, null, '{"foo":"bar"}')));
+ $result = array();
+ $visitor->before($command, $result);
+ $this->assertEquals(array('foo' => 'bar'), $result);
+ }
+
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'array',
+ 'items' => array(
+ 'filters' => 'strtoupper',
+ 'type' => 'string'
+ )
+ ));
+ $this->value = array('foo' => array('a', 'b', 'c'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('A', 'B', 'C'), $this->value['foo']);
+ }
+
+ public function testRenamesTopLevelValues()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'sentAs' => 'Baz',
+ 'type' => 'string',
+ ));
+ $this->value = array('Baz' => 'test');
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('foo' => 'test'), $this->value);
+ }
+
+ public function testRenamesDoesNotFailForNonExistentKey()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'properties' => array(
+ 'bar' => array(
+ 'name' => 'bar',
+ 'sentAs' => 'baz',
+ ),
+ ),
+ ));
+ $this->value = array('foo' => array('unknown' => 'Unknown'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('foo' => array('unknown' => 'Unknown')), $this->value);
+ }
+
+ public function testTraversesObjectsAndAppliesFilters()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'properties' => array(
+ 'foo' => array('filters' => 'strtoupper'),
+ 'bar' => array('filters' => 'strtolower')
+ )
+ ));
+ $this->value = array('foo' => array('foo' => 'hello', 'bar' => 'THERE'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('foo' => 'HELLO', 'bar' => 'there'), $this->value['foo']);
+ }
+
+ /**
+ * @group issue-399
+ * @link https://github.com/guzzle/guzzle/issues/399
+ */
+ public function testDiscardingUnknownProperties()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'additionalProperties' => false,
+ 'properties' => array(
+ 'bar' => array(
+ 'type' => 'string',
+ 'name' => 'bar',
+ ),
+ ),
+ ));
+ $this->value = array('foo' => array('bar' => 15, 'unknown' => 'Unknown'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('foo' => array('bar' => 15)), $this->value);
+ }
+
+ /**
+ * @group issue-399
+ * @link https://github.com/guzzle/guzzle/issues/399
+ */
+ public function testDiscardingUnknownPropertiesWithAliasing()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'additionalProperties' => false,
+ 'properties' => array(
+ 'bar' => array(
+ 'name' => 'bar',
+ 'sentAs' => 'baz',
+ ),
+ ),
+ ));
+ $this->value = array('foo' => array('baz' => 15, 'unknown' => 'Unknown'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('foo' => array('bar' => 15)), $this->value);
+ }
+
+ public function testWalksAdditionalProperties()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'additionalProperties' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'bar' => array(
+ 'type' => 'string',
+ 'filters' => array('base64_decode')
+ )
+ ),
+ ),
+ ));
+ $this->value = array('foo' => array('baz' => array('bar' => 'Zm9v')));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals('foo', $this->value['foo']['baz']['bar']);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/ReasonPhraseVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/ReasonPhraseVisitorTest.php
new file mode 100644
index 0000000..23cd40f
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/ReasonPhraseVisitorTest.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Command\LocationVisitor\Response\ReasonPhraseVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Response\ReasonPhraseVisitor
+ */
+class ReasonPhraseVisitorTest extends AbstractResponseVisitorTest
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array('location' => 'reasonPhrase', 'name' => 'phrase'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals('OK', $this->value['phrase']);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/StatusCodeVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/StatusCodeVisitorTest.php
new file mode 100644
index 0000000..7211a58
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/StatusCodeVisitorTest.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Command\LocationVisitor\Response\StatusCodeVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Response\StatusCodeVisitor
+ */
+class StatusCodeVisitorTest extends AbstractResponseVisitorTest
+{
+ public function testVisitsLocation()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array('location' => 'statusCode', 'name' => 'code'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(200, $this->value['code']);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/XmlVisitorTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/XmlVisitorTest.php
new file mode 100644
index 0000000..f87cec7
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response/XmlVisitorTest.php
@@ -0,0 +1,431 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command\LocationVisitor\Response;
+
+use Guzzle\Service\Description\Parameter;
+use Guzzle\Http\Message\Response;
+use Guzzle\Service\Command\LocationVisitor\Response\XmlVisitor as Visitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\Response\XmlVisitor
+ */
+class XmlVisitorTest extends AbstractResponseVisitorTest
+{
+ public function testBeforeMethodParsesXml()
+ {
+ $visitor = new Visitor();
+ $command = $this->getMockBuilder('Guzzle\Service\Command\AbstractCommand')
+ ->setMethods(array('getResponse'))
+ ->getMockForAbstractClass();
+ $command->expects($this->once())
+ ->method('getResponse')
+ ->will($this->returnValue(new Response(200, null, '<foo><Bar>test</Bar></foo>')));
+ $result = array();
+ $visitor->before($command, $result);
+ $this->assertEquals(array('Bar' => 'test'), $result);
+ }
+
+ public function testBeforeMethodParsesXmlWithNamespace()
+ {
+ $this->markTestSkipped("Response/XmlVisitor cannot accept 'xmlns' in response, see #368 (http://git.io/USa1mA).");
+
+ $visitor = new Visitor();
+ $command = $this->getMockBuilder('Guzzle\Service\Command\AbstractCommand')
+ ->setMethods(array('getResponse'))
+ ->getMockForAbstractClass();
+ $command->expects($this->once())
+ ->method('getResponse')
+ ->will($this->returnValue(new Response(200, null, '<foo xmlns="urn:foo"><bar:Bar xmlns:bar="urn:bar">test</bar:Bar></foo>')));
+ $result = array();
+ $visitor->before($command, $result);
+ $this->assertEquals(array('Bar' => 'test'), $result);
+ }
+
+ public function testBeforeMethodParsesNestedXml()
+ {
+ $visitor = new Visitor();
+ $command = $this->getMockBuilder('Guzzle\Service\Command\AbstractCommand')
+ ->setMethods(array('getResponse'))
+ ->getMockForAbstractClass();
+ $command->expects($this->once())
+ ->method('getResponse')
+ ->will($this->returnValue(new Response(200, null, '<foo><Items><Bar>test</Bar></Items></foo>')));
+ $result = array();
+ $visitor->before($command, $result);
+ $this->assertEquals(array('Items' => array('Bar' => 'test')), $result);
+ }
+
+ public function testCanExtractAndRenameTopLevelXmlValues()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'xml',
+ 'name' => 'foo',
+ 'sentAs' => 'Bar'
+ ));
+ $value = array('Bar' => 'test');
+ $visitor->visit($this->command, $this->response, $param, $value);
+ $this->assertArrayHasKey('foo', $value);
+ $this->assertEquals('test', $value['foo']);
+ }
+
+ public function testEnsuresRepeatedArraysAreInCorrectLocations()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'xml',
+ 'name' => 'foo',
+ 'sentAs' => 'Foo',
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'Bar' => array('type' => 'string'),
+ 'Baz' => array('type' => 'string'),
+ 'Bam' => array('type' => 'string')
+ )
+ )
+ ));
+
+ $xml = new \SimpleXMLElement('<Test><Foo><Bar>1</Bar><Baz>2</Baz></Foo></Test>');
+ $value = json_decode(json_encode($xml), true);
+ $visitor->visit($this->command, $this->response, $param, $value);
+ $this->assertEquals(array(
+ 'foo' => array(
+ array (
+ 'Bar' => '1',
+ 'Baz' => '2'
+ )
+ )
+ ), $value);
+ }
+
+ public function testEnsuresFlatArraysAreFlat()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'location' => 'xml',
+ 'name' => 'foo',
+ 'type' => 'array',
+ 'items' => array('type' => 'string')
+ ));
+
+ $value = array('foo' => array('bar', 'baz'));
+ $visitor->visit($this->command, $this->response, $param, $value);
+ $this->assertEquals(array('foo' => array('bar', 'baz')), $value);
+
+ $value = array('foo' => 'bar');
+ $visitor->visit($this->command, $this->response, $param, $value);
+ $this->assertEquals(array('foo' => array('bar')), $value);
+ }
+
+ public function xmlDataProvider()
+ {
+ $param = new Parameter(array(
+ 'location' => 'xml',
+ 'name' => 'Items',
+ 'type' => 'array',
+ 'items' => array(
+ 'type' => 'object',
+ 'name' => 'Item',
+ 'properties' => array(
+ 'Bar' => array('type' => 'string'),
+ 'Baz' => array('type' => 'string')
+ )
+ )
+ ));
+
+ return array(
+ array($param, '<Test><Items><Item><Bar>1</Bar></Item><Item><Bar>2</Bar></Item></Items></Test>', array(
+ 'Items' => array(
+ array('Bar' => 1),
+ array('Bar' => 2)
+ )
+ )),
+ array($param, '<Test><Items><Item><Bar>1</Bar></Item></Items></Test>', array(
+ 'Items' => array(
+ array('Bar' => 1)
+ )
+ )),
+ array($param, '<Test><Items /></Test>', array(
+ 'Items' => array()
+ ))
+ );
+ }
+
+ /**
+ * @dataProvider xmlDataProvider
+ */
+ public function testEnsuresWrappedArraysAreInCorrectLocations($param, $xml, $result)
+ {
+ $visitor = new Visitor();
+ $xml = new \SimpleXMLElement($xml);
+ $value = json_decode(json_encode($xml), true);
+ $visitor->visit($this->command, $this->response, $param, $value);
+ $this->assertEquals($result, $value);
+ }
+
+ public function testCanRenameValues()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'TerminatingInstances',
+ 'type' => 'array',
+ 'location' => 'xml',
+ 'sentAs' => 'instancesSet',
+ 'items' => array(
+ 'name' => 'item',
+ 'type' => 'object',
+ 'sentAs' => 'item',
+ 'properties' => array(
+ 'InstanceId' => array(
+ 'type' => 'string',
+ 'sentAs' => 'instanceId',
+ ),
+ 'CurrentState' => array(
+ 'type' => 'object',
+ 'sentAs' => 'currentState',
+ 'properties' => array(
+ 'Code' => array(
+ 'type' => 'numeric',
+ 'sentAs' => 'code',
+ ),
+ 'Name' => array(
+ 'type' => 'string',
+ 'sentAs' => 'name',
+ ),
+ ),
+ ),
+ 'PreviousState' => array(
+ 'type' => 'object',
+ 'sentAs' => 'previousState',
+ 'properties' => array(
+ 'Code' => array(
+ 'type' => 'numeric',
+ 'sentAs' => 'code',
+ ),
+ 'Name' => array(
+ 'type' => 'string',
+ 'sentAs' => 'name',
+ ),
+ ),
+ ),
+ ),
+ )
+ ));
+
+ $value = array(
+ 'instancesSet' => array (
+ 'item' => array (
+ 'instanceId' => 'i-3ea74257',
+ 'currentState' => array(
+ 'code' => '32',
+ 'name' => 'shutting-down',
+ ),
+ 'previousState' => array(
+ 'code' => '16',
+ 'name' => 'running',
+ ),
+ ),
+ )
+ );
+
+ $visitor->visit($this->command, $this->response, $param, $value);
+
+ $this->assertEquals(array(
+ 'TerminatingInstances' => array(
+ array(
+ 'InstanceId' => 'i-3ea74257',
+ 'CurrentState' => array(
+ 'Code' => '32',
+ 'Name' => 'shutting-down',
+ ),
+ 'PreviousState' => array(
+ 'Code' => '16',
+ 'Name' => 'running',
+ )
+ )
+ )
+ ), $value);
+ }
+
+ public function testCanRenameAttributes()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'RunningQueues',
+ 'type' => 'array',
+ 'location' => 'xml',
+ 'items' => array(
+ 'type' => 'object',
+ 'sentAs' => 'item',
+ 'properties' => array(
+ 'QueueId' => array(
+ 'type' => 'string',
+ 'sentAs' => 'queue_id',
+ 'data' => array(
+ 'xmlAttribute' => true,
+ ),
+ ),
+ 'CurrentState' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'Code' => array(
+ 'type' => 'numeric',
+ 'sentAs' => 'code',
+ 'data' => array(
+ 'xmlAttribute' => true,
+ ),
+ ),
+ 'Name' => array(
+ 'sentAs' => 'name',
+ 'data' => array(
+ 'xmlAttribute' => true,
+ ),
+ ),
+ ),
+ ),
+ 'PreviousState' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'Code' => array(
+ 'type' => 'numeric',
+ 'sentAs' => 'code',
+ 'data' => array(
+ 'xmlAttribute' => true,
+ ),
+ ),
+ 'Name' => array(
+ 'sentAs' => 'name',
+ 'data' => array(
+ 'xmlAttribute' => true,
+ ),
+ ),
+ ),
+ ),
+ ),
+ )
+ ));
+
+ $xml = '<wrap><RunningQueues><item queue_id="q-3ea74257"><CurrentState code="32" name="processing" /><PreviousState code="16" name="wait" /></item></RunningQueues></wrap>';
+ $value = json_decode(json_encode(new \SimpleXMLElement($xml)), true);
+ $visitor->visit($this->command, $this->response, $param, $value);
+
+ $this->assertEquals(array(
+ 'RunningQueues' => array(
+ array(
+ 'QueueId' => 'q-3ea74257',
+ 'CurrentState' => array(
+ 'Code' => '32',
+ 'Name' => 'processing',
+ ),
+ 'PreviousState' => array(
+ 'Code' => '16',
+ 'Name' => 'wait',
+ ),
+ ),
+ )
+ ), $value);
+ }
+
+ public function testAddsEmptyArraysWhenValueIsMissing()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'Foo',
+ 'type' => 'array',
+ 'location' => 'xml',
+ 'items' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'Baz' => array('type' => 'array'),
+ 'Bar' => array(
+ 'type' => 'object',
+ 'properties' => array(
+ 'Baz' => array('type' => 'array'),
+ )
+ )
+ )
+ )
+ ));
+
+ $value = array();
+ $visitor->visit($this->command, $this->response, $param, $value);
+
+ $value = array(
+ 'Foo' => array(
+ 'Bar' => array()
+ )
+ );
+ $visitor->visit($this->command, $this->response, $param, $value);
+ $this->assertEquals(array(
+ 'Foo' => array(
+ array(
+ 'Bar' => array()
+ )
+ )
+ ), $value);
+ }
+
+ /**
+ * @group issue-399
+ * @link https://github.com/guzzle/guzzle/issues/399
+ */
+ public function testDiscardingUnknownProperties()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'additionalProperties' => false,
+ 'properties' => array(
+ 'bar' => array(
+ 'type' => 'string',
+ 'name' => 'bar',
+ ),
+ ),
+ ));
+ $this->value = array('foo' => array('bar' => 15, 'unknown' => 'Unknown'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('foo' => array('bar' => 15)), $this->value);
+ }
+
+ /**
+ * @group issue-399
+ * @link https://github.com/guzzle/guzzle/issues/399
+ */
+ public function testDiscardingUnknownPropertiesWithAliasing()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'additionalProperties' => false,
+ 'properties' => array(
+ 'bar' => array(
+ 'name' => 'bar',
+ 'sentAs' => 'baz',
+ ),
+ ),
+ ));
+ $this->value = array('foo' => array('baz' => 15, 'unknown' => 'Unknown'));
+ $visitor->visit($this->command, $this->response, $param, $this->value);
+ $this->assertEquals(array('foo' => array('bar' => 15)), $this->value);
+ }
+
+ public function testProperlyHandlesEmptyStringValues()
+ {
+ $visitor = new Visitor();
+ $param = new Parameter(array(
+ 'name' => 'foo',
+ 'type' => 'object',
+ 'properties' => array(
+ 'bar' => array('type' => 'string')
+ ),
+ ));
+ $xml = '<wrapper><foo><bar /></foo></wrapper>';
+ $value = json_decode(json_encode(new \SimpleXMLElement($xml)), true);
+ $visitor->visit($this->command, $this->response, $param, $value);
+ $this->assertEquals(array('foo' => array('bar' => '')), $value);
+ }
+}
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/VisitorFlyweightTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/VisitorFlyweightTest.php
new file mode 100644
index 0000000..a252ffe
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/VisitorFlyweightTest.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Guzzle\Tests\Service\Command;
+
+use Guzzle\Service\Command\LocationVisitor\VisitorFlyweight;
+use Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor as JsonRequestVisitor;
+use Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor as JsonResponseVisitor;
+
+/**
+ * @covers Guzzle\Service\Command\LocationVisitor\VisitorFlyweight
+ */
+class VisitorFlyweightTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ public function testUsesDefaultMappingsWithGetInstance()
+ {
+ $f = VisitorFlyweight::getInstance();
+ $this->assertInstanceOf('Guzzle\Service\Command\LocationVisitor\Request\JsonVisitor', $f->getRequestVisitor('json'));
+ $this->assertInstanceOf('Guzzle\Service\Command\LocationVisitor\Response\JsonVisitor', $f->getResponseVisitor('json'));
+ }
+
+ public function testCanUseCustomMappings()
+ {
+ $f = new VisitorFlyweight(array());
+ $this->assertEquals(array(), $this->readAttribute($f, 'mappings'));
+ }
+
+ /**
+ * @expectedException \InvalidArgumentException
+ * @expectedExceptionMessage No request visitor has been mapped for foo
+ */
+ public function testThrowsExceptionWhenRetrievingUnknownVisitor()
+ {
+ VisitorFlyweight::getInstance()->getRequestVisitor('foo');
+ }
+
+ public function testCachesVisitors()
+ {
+ $f = new VisitorFlyweight();
+ $v1 = $f->getRequestVisitor('json');
+ $this->assertSame($v1, $f->getRequestVisitor('json'));
+ }
+
+ public function testAllowsAddingVisitors()
+ {
+ $f = new VisitorFlyweight();
+ $j1 = new JsonRequestVisitor();
+ $j2 = new JsonResponseVisitor();
+ $f->addRequestVisitor('json', $j1);
+ $f->addResponseVisitor('json', $j2);
+ $this->assertSame($j1, $f->getRequestVisitor('json'));
+ $this->assertSame($j2, $f->getResponseVisitor('json'));
+ }
+}