summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/tests/Guzzle/Tests/Service/Command/LocationVisitor/Response')
-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
7 files changed, 778 insertions, 0 deletions
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);
+ }
+}