1
0
mirror of https://github.com/guzzle/guzzle.git synced 2025-02-25 10:33:18 +01:00

Renaming the rename attribute of inputs and outputs to sentAs

- sentAs represents how the data is named over the wire
- name represents how the data is represented in the input and output hash
Fixing nested renaming of XML response marshaling
This commit is contained in:
Michael Dowling 2012-10-08 15:25:28 -07:00
parent c7918d79ca
commit b4a9ab6f91
27 changed files with 115 additions and 116 deletions

View File

@ -35,7 +35,7 @@ abstract class AbstractRequestVisitor implements RequestVisitorInterface
{ {
foreach ($value as $name => $v) { foreach ($value as $name => $v) {
if ($subParam = $param->getProperty($name)) { if ($subParam = $param->getProperty($name)) {
$key = $subParam->getKey(); $key = $subParam->getWireName();
if (is_array($v)) { if (is_array($v)) {
$value[$key] = $this->resolveRecursively($v, $subParam); $value[$key] = $this->resolveRecursively($v, $subParam);
} elseif ($name != $key) { } elseif ($name != $key) {

View File

@ -16,6 +16,6 @@ class HeaderVisitor extends AbstractRequestVisitor
*/ */
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{ {
$request->setHeader($param->getKey(), $value); $request->setHeader($param->getWireName(), $value);
} }
} }

View File

@ -50,7 +50,7 @@ class JsonVisitor extends AbstractRequestVisitor
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{ {
$json = isset($this->data[$command]) ? $this->data[$command] : array(); $json = isset($this->data[$command]) ? $this->data[$command] : array();
$json[$param->getKey()] = $param && is_array($value) $json[$param->getWireName()] = $param && is_array($value)
? $this->resolveRecursively($value, $param) ? $this->resolveRecursively($value, $param)
: $value; : $value;
$this->data[$command] = $json; $this->data[$command] = $json;
@ -64,7 +64,7 @@ class JsonVisitor extends AbstractRequestVisitor
if (isset($this->data[$command])) { if (isset($this->data[$command])) {
$json = $this->data[$command]; $json = $this->data[$command];
unset($this->data[$command]); unset($this->data[$command]);
$request->setBody(json_encode($json))->removeHeader('Expect'); $request->setBody(json_encode($json));
if ($this->jsonContentType) { if ($this->jsonContentType) {
$request->setHeader('Content-Type', $this->jsonContentType); $request->setHeader('Content-Type', $this->jsonContentType);
} }

View File

@ -17,7 +17,7 @@ class PostFieldVisitor extends AbstractRequestVisitor
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{ {
$request->setPostField( $request->setPostField(
$param->getKey(), $param->getWireName(),
$param && is_array($value) ? $this->resolveRecursively($value, $param) : $value $param && is_array($value) ? $this->resolveRecursively($value, $param) : $value
); );
} }

View File

@ -20,7 +20,7 @@ class PostFileVisitor extends AbstractRequestVisitor
if ($value instanceof PostFileInterface) { if ($value instanceof PostFileInterface) {
$request->addPostFile($value); $request->addPostFile($value);
} else { } else {
$request->addPostFile($param->getKey(), $value); $request->addPostFile($param->getWireName(), $value);
} }
} }
} }

View File

@ -17,7 +17,7 @@ class QueryVisitor extends AbstractRequestVisitor
public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value) public function visit(CommandInterface $command, RequestInterface $request, Parameter $param, $value)
{ {
$request->getQuery()->set( $request->getQuery()->set(
$param->getKey(), $param->getWireName(),
$param && is_array($value) ? $this->resolveRecursively($value, $param) : $value $param && is_array($value) ? $this->resolveRecursively($value, $param) : $value
); );
} }

View File

@ -67,7 +67,7 @@ class XmlVisitor extends AbstractRequestVisitor
$node = $xml; $node = $xml;
if ($param->getType() == 'object' || $param->getType() == 'array') { if ($param->getType() == 'object' || $param->getType() == 'array') {
$node = $xml->addChild($param->getKey()); $node = $xml->addChild($param->getWireName());
} }
$this->addXml($node, $param, $value); $this->addXml($node, $param, $value);
@ -82,7 +82,7 @@ class XmlVisitor extends AbstractRequestVisitor
if (isset($this->data[$command])) { if (isset($this->data[$command])) {
$xml = $this->data[$command]; $xml = $this->data[$command];
unset($this->data[$command]); unset($this->data[$command]);
$request->setBody($xml->asXML())->removeHeader('Expect'); $request->setBody($xml->asXML());
if ($this->contentType) { if ($this->contentType) {
$request->setHeader('Content-Type', $this->contentType); $request->setHeader('Content-Type', $this->contentType);
} }
@ -99,13 +99,13 @@ class XmlVisitor extends AbstractRequestVisitor
protected function addXml(\SimpleXMLElement $xml, Parameter $param, $value) protected function addXml(\SimpleXMLElement $xml, Parameter $param, $value)
{ {
// Determine the name of the element // Determine the name of the element
$node = $param->getKey(); $node = $param->getWireName();
// Check if this property has a particular namespace // Check if this property has a particular namespace
$namespace = $param->getData('namespace') ?: null; $namespace = $param->getData('namespace') ?: null;
if ($param->getType() == 'array') { if ($param->getType() == 'array') {
if ($items = $param->getItems()) { if ($items = $param->getItems()) {
$name = $items->getKey(); $name = $items->getWireName();
foreach ($value as $v) { foreach ($value as $v) {
if ($items->getType() == 'object' || $items->getType() == 'array') { if ($items->getType() == 'object' || $items->getType() == 'array') {
$child = $xml->addChild($name, null, $namespace); $child = $xml->addChild($name, null, $namespace);
@ -119,13 +119,13 @@ class XmlVisitor extends AbstractRequestVisitor
foreach ($value as $name => $v) { foreach ($value as $name => $v) {
if ($property = $param->getProperty($name)) { if ($property = $param->getProperty($name)) {
if ($property->getType() == 'object' || $property->getType() == 'array') { if ($property->getType() == 'object' || $property->getType() == 'array') {
$child = $xml->addChild($name); $child = $xml->addChild($property->getWireName());
$this->addXml($child, $property, $v); $this->addXml($child, $property, $v);
} else { } else {
if ($property->getData('attribute')) { if ($property->getData('attribute')) {
$xml->addAttribute($property->getKey(), $v, $namespace); $xml->addAttribute($property->getWireName(), $v, $namespace);
} else { } else {
$xml->addChild($name, $v, $namespace); $xml->addChild($property->getWireName(), $v, $namespace);
} }
} }
} }

View File

@ -16,6 +16,6 @@ class BodyVisitor extends AbstractResponseVisitor
*/ */
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value) public function visit(CommandInterface $command, Response $response, Parameter $param, &$value)
{ {
$value[$param->getKey()] = $response->getBody(); $value[$param->getName()] = $response->getBody();
} }
} }

View File

@ -16,6 +16,6 @@ class HeaderVisitor extends AbstractResponseVisitor
*/ */
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value) public function visit(CommandInterface $command, Response $response, Parameter $param, &$value)
{ {
$value[$param->getKey()] = (string) $response->getHeader($param->getName()); $value[$param->getName()] = (string) $response->getHeader($param->getWireName());
} }
} }

View File

@ -10,10 +10,9 @@ use Guzzle\Service\Command\CommandInterface;
* Location visitor used to marshal JSON response data into a formatted array. * Location visitor used to marshal JSON response data into a formatted array.
* *
* Allows top level JSON parameters to be inserted into the result of a command. The top level attributes are grabbed * Allows top level JSON parameters to be inserted into the result of a command. The top level attributes are grabbed
* from the response's JSON data using the name value by default. If a `rename` property is set on a top level model * from the response's JSON data using the name value by default. Filters can be applied to parameters as they are
* property, then the value will be grabbed from the JSON response using the `rename` property, but stored in the result * traversed. This allows data to be normalized before returning it to users (for example converting timestamps to
* array using the `name` key. Filters can be applied to parameters as they are traversed. This allows data to be * DateTime objects).
* normalized before returning it to users (for example converting timestamps to DateTime objects).
*/ */
class JsonVisitor extends AbstractResponseVisitor class JsonVisitor extends AbstractResponseVisitor
{ {
@ -23,7 +22,7 @@ class JsonVisitor extends AbstractResponseVisitor
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value) public function visit(CommandInterface $command, Response $response, Parameter $param, &$value)
{ {
$name = $param->getName(); $name = $param->getName();
$key = $param->getKey(); $key = $param->getWireName();
if (isset($value[$key])) { if (isset($value[$key])) {
$this->recursiveProcess($param, $value[$key]); $this->recursiveProcess($param, $value[$key]);
if ($key != $name) { if ($key != $name) {

View File

@ -16,6 +16,6 @@ class ReasonPhraseVisitor extends AbstractResponseVisitor
*/ */
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value) public function visit(CommandInterface $command, Response $response, Parameter $param, &$value)
{ {
$value[$param->getKey()] = $response->getReasonPhrase(); $value[$param->getName()] = $response->getReasonPhrase();
} }
} }

View File

@ -16,6 +16,6 @@ class StatusCodeVisitor extends AbstractResponseVisitor
*/ */
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value) public function visit(CommandInterface $command, Response $response, Parameter $param, &$value)
{ {
$value[$param->getKey()] = $response->getStatusCode(); $value[$param->getName()] = $response->getStatusCode();
} }
} }

View File

@ -16,13 +16,13 @@ class XmlVisitor extends AbstractResponseVisitor
*/ */
public function visit(CommandInterface $command, Response $response, Parameter $param, &$value) public function visit(CommandInterface $command, Response $response, Parameter $param, &$value)
{ {
$sentAs = $param->getWireName();
if (isset($value[$sentAs])) {
$this->recursiveProcess($param, $value[$sentAs]);
$name = $param->getName(); $name = $param->getName();
if (isset($value[$name])) { if ($name != $sentAs) {
$this->recursiveProcess($param, $value[$name]); $value[$name] = $value[$sentAs];
$rename = $param->getRename(); unset($value[$sentAs]);
if ($rename && $rename != $name) {
$value[$rename] = $value[$name];
unset($value[$name]);
} }
} }
} }
@ -69,13 +69,13 @@ class XmlVisitor extends AbstractResponseVisitor
// On the above line, we ensure that the array is associative and not numerically indexed // On the above line, we ensure that the array is associative and not numerically indexed
if ($properties = $param->getProperties()) { if ($properties = $param->getProperties()) {
foreach ($properties as $property) { foreach ($properties as $property) {
$sentAs = $property->getWireName();
if (isset($value[$sentAs])) {
$this->recursiveProcess($property, $value[$sentAs]);
$name = $property->getName(); $name = $property->getName();
if (isset($value[$name])) { if ($name != $sentAs) {
$this->recursiveProcess($property, $value[$name]); $value[$name] = $value[$sentAs];
$rename = $property->getRename(); unset($value[$sentAs]);
if ($rename && $rename != $name) {
$value[$rename] = $value[$name];
unset($value[$name]);
} }
} }
} }

View File

@ -26,7 +26,7 @@ class Parameter
protected $instanceOf; protected $instanceOf;
protected $filters; protected $filters;
protected $location; protected $location;
protected $rename; protected $sentAs;
protected $data; protected $data;
protected $properties = array(); protected $properties = array();
protected $additionalProperties; protected $additionalProperties;
@ -48,9 +48,9 @@ class Parameter
* - description: (string) Documentation of the parameter * - description: (string) Documentation of the parameter
* - location: (string) The location of a request used to apply a parameter. Custom locations can be registered * - location: (string) The location of a request used to apply a parameter. Custom locations can be registered
* with a command, but the defaults are uri, query, header, body, json, postField, postFile. * with a command, but the defaults are uri, query, header, body, json, postField, postFile.
* - rename: (string) Allows the customization of where in a location a parameter is applied. If a parameter * - sentAs: (string) Specifies how the data being modeled is sent over the wire. For example, you may wish
* is named foo, has a location of query, and a rename of 'Bar', the parameter will be added to the * to include certain headers in a response model that have a normalized casing of FooBar, but the
* query string of a request using `Bar` as the key. * actual header is x-foo-bar. In this case, sentAs would be set to x-foo-bar.
* - filters: (array) Array of static method names to to run a parameter value through. Each value in the * - filters: (array) Array of static method names to to run a parameter value through. Each value in the
* array must be a string containing the full class path to a static method or an array of complex * array must be a string containing the full class path to a static method or an array of complex
* filter information. You can specify static methods of classes using the full namespace class * filter information. You can specify static methods of classes using the full namespace class
@ -131,7 +131,7 @@ class Parameter
public function toArray() public function toArray()
{ {
$result = array(); $result = array();
$checks = array('required', 'description', 'static', 'type', 'instanceOf', 'location', 'rename', 'pattern', $checks = array('required', 'description', 'static', 'type', 'instanceOf', 'location', 'sentAs', 'pattern',
'minimum', 'maximum', 'minItems', 'maxItems', 'minLength', 'maxLength', 'data', 'enum', 'filters'); 'minimum', 'maximum', 'minItems', 'maxItems', 'minLength', 'maxLength', 'data', 'enum', 'filters');
// Anything that is in the `Items` attribute of an array *must* include it's name if available // Anything that is in the `Items` attribute of an array *must* include it's name if available
@ -220,13 +220,13 @@ class Parameter
} }
/** /**
* Get the key of the parameter, where rename will supercede name if it is set * Get the key of the parameter, where sentAs will supersede name if it is set
* *
* @return string * @return string
*/ */
public function getKey() public function getWireName()
{ {
return $this->rename ?: $this->name; return $this->sentAs ?: $this->name;
} }
/** /**
@ -508,26 +508,26 @@ class Parameter
} }
/** /**
* Get the rename attribute of the parameter that used with locations to rename an attribute when it is being * Get the sentAs attribute of the parameter that used with locations to sentAs an attribute when it is being
* applied to a location. * applied to a location.
* *
* @return string|null * @return string|null
*/ */
public function getRename() public function getSentAs()
{ {
return $this->rename; return $this->sentAs;
} }
/** /**
* Set the rename attribute * Set the sentAs attribute
* *
* @param string|null $name Rename value * @param string|null $name Name of the value as it is sent over the wire
* *
* @return self * @return self
*/ */
public function setRename($name) public function setSentAs($name)
{ {
$this->rename = $name; $this->sentAs = $name;
return $this; return $this;
} }

View File

@ -40,7 +40,7 @@ abstract class AbstractVisitorTestCase extends \Guzzle\Tests\GuzzleTestCase
'foo' => new Parameter(array( 'foo' => new Parameter(array(
'type' => 'object', 'type' => 'object',
'location' => $location, 'location' => $location,
'location_key' => 'Foo', 'sentAs' => 'Foo',
'required' => true, 'required' => true,
'properties' => array( 'properties' => array(
'test' => array( 'test' => array(
@ -51,11 +51,10 @@ abstract class AbstractVisitorTestCase extends \Guzzle\Tests\GuzzleTestCase
'type' => 'boolean', 'type' => 'boolean',
'default' => true 'default' => true
), ),
// Add a nested parameter that uses a different location_key than the input key
'jenga' => array( 'jenga' => array(
'type' => 'string', 'type' => 'string',
'default' => 'hello', 'default' => 'hello',
'rename' => 'Jenga_Yall!', 'sentAs' => 'Jenga_Yall!',
'filters' => array('strtoupper') 'filters' => array('strtoupper')
) )
) )

View File

@ -12,7 +12,7 @@ class BodyVisitorTest extends AbstractVisitorTestCase
public function testVisitsLocation() public function testVisitsLocation()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('body')->getParam('foo')->setRename('Foo'); $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
$visitor->visit($this->command, $this->request, $param, '123'); $visitor->visit($this->command, $this->request, $param, '123');
$this->assertEquals('123', (string) $this->request->getBody()); $this->assertEquals('123', (string) $this->request->getBody());
$this->assertNull($this->request->getHeader('Expect')); $this->assertNull($this->request->getHeader('Expect'));
@ -21,7 +21,7 @@ class BodyVisitorTest extends AbstractVisitorTestCase
public function testAddsExpectHeaderWhenSetToTrue() public function testAddsExpectHeaderWhenSetToTrue()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('body')->getParam('foo')->setRename('Foo'); $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
$param->setData('expect_header', true); $param->setData('expect_header', true);
$visitor->visit($this->command, $this->request, $param, '123'); $visitor->visit($this->command, $this->request, $param, '123');
$this->assertEquals('123', (string) $this->request->getBody()); $this->assertEquals('123', (string) $this->request->getBody());
@ -30,7 +30,7 @@ class BodyVisitorTest extends AbstractVisitorTestCase
public function testCanDisableExpectHeader() public function testCanDisableExpectHeader()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('body')->getParam('foo')->setRename('Foo'); $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
$param->setData('expect_header', false); $param->setData('expect_header', false);
$visitor->visit($this->command, $this->request, $param, '123'); $visitor->visit($this->command, $this->request, $param, '123');
$this->assertNull($this->request->getHeader('Expect')); $this->assertNull($this->request->getHeader('Expect'));
@ -39,7 +39,7 @@ class BodyVisitorTest extends AbstractVisitorTestCase
public function testCanSetExpectHeaderBasedOnSize() public function testCanSetExpectHeaderBasedOnSize()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('body')->getParam('foo')->setRename('Foo'); $param = $this->getNestedCommand('body')->getParam('foo')->setSentAs('Foo');
// The body is less than the cutoff // The body is less than the cutoff
$param->setData('expect_header', 5); $param->setData('expect_header', 5);
$visitor->visit($this->command, $this->request, $param, '123'); $visitor->visit($this->command, $this->request, $param, '123');

View File

@ -12,7 +12,7 @@ class HeaderVisitorTest extends AbstractVisitorTestCase
public function testVisitsLocation() public function testVisitsLocation()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('header')->getParam('foo')->setRename('test'); $param = $this->getNestedCommand('header')->getParam('foo')->setSentAs('test');
$visitor->visit($this->command, $this->request, $param, '123'); $visitor->visit($this->command, $this->request, $param, '123');
$this->assertEquals('123', (string) $this->request->getHeader('test')); $this->assertEquals('123', (string) $this->request->getHeader('test'));
} }

View File

@ -16,8 +16,8 @@ class JsonVisitorTest extends AbstractVisitorTestCase
$visitor->after($this->command, $this->request); $visitor->after($this->command, $this->request);
$param = $this->getNestedCommand('json')->getParam('foo'); $param = $this->getNestedCommand('json')->getParam('foo');
$visitor->visit($this->command, $this->request, $param->setRename('test'), '123'); $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
$visitor->visit($this->command, $this->request, $param->setRename('test2'), 'abc'); $visitor->visit($this->command, $this->request, $param->setSentAs('test2'), 'abc');
$visitor->after($this->command, $this->request); $visitor->after($this->command, $this->request);
$this->assertEquals('{"test":"123","test2":"abc"}', (string) $this->request->getBody()); $this->assertEquals('{"test":"123","test2":"abc"}', (string) $this->request->getBody());
} }
@ -27,7 +27,7 @@ class JsonVisitorTest extends AbstractVisitorTestCase
$visitor = new Visitor(); $visitor = new Visitor();
$visitor->setContentTypeHeader('application/json-foo'); $visitor->setContentTypeHeader('application/json-foo');
$param = $this->getNestedCommand('json')->getParam('foo'); $param = $this->getNestedCommand('json')->getParam('foo');
$visitor->visit($this->command, $this->request, $param->setRename('test'), '123'); $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
$visitor->after($this->command, $this->request); $visitor->after($this->command, $this->request);
$this->assertEquals('application/json-foo', (string) $this->request->getHeader('Content-Type')); $this->assertEquals('application/json-foo', (string) $this->request->getHeader('Content-Type'));
} }
@ -42,7 +42,7 @@ class JsonVisitorTest extends AbstractVisitorTestCase
$request = $command->prepare(); $request = $command->prepare();
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('json')->getParam('foo'); $param = $this->getNestedCommand('json')->getParam('foo');
$visitor->visit($command, $request, $param->setRename('Foo'), $command['foo']); $visitor->visit($command, $request, $param->setSentAs('Foo'), $command['foo']);
$visitor->after($command, $request); $visitor->after($command, $request);
$this->assertEquals('{"Foo":{"test":{"baz":true,"Jenga_Yall!":"HELLO"},"bar":123}}', (string) $request->getBody()); $this->assertEquals('{"Foo":{"test":{"baz":true,"Jenga_Yall!":"HELLO"},"bar":123}}', (string) $request->getBody());
} }

View File

@ -13,14 +13,13 @@ class PostFieldVisitorTest extends AbstractVisitorTestCase
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('postField')->getParam('foo'); $param = $this->getNestedCommand('postField')->getParam('foo');
$visitor->visit($this->command, $this->request, $param->setRename('test'), '123'); $visitor->visit($this->command, $this->request, $param->setSentAs('test'), '123');
$this->assertEquals('123', (string) $this->request->getPostField('test')); $this->assertEquals('123', (string) $this->request->getPostField('test'));
} }
public function testRecursivelyBuildsPostFields() public function testRecursivelyBuildsPostFields()
{ {
$command = $this->getCommand('postField'); $command = $this->getCommand('postField');
$command->getOperation()->getParam('foo')->setRename('Foo');
$request = $command->prepare(); $request = $command->prepare();
$visitor = new Visitor(); $visitor = new Visitor();
$param = $command->getOperation()->getParam('foo'); $param = $command->getOperation()->getParam('foo');

View File

@ -16,11 +16,11 @@ class PostFileVisitorTest extends AbstractVisitorTestCase
$param = $this->getNestedCommand('postFile')->getParam('foo'); $param = $this->getNestedCommand('postFile')->getParam('foo');
// Test using a path to a file // Test using a path to a file
$visitor->visit($this->command, $this->request, $param->setRename('test_3'), __FILE__); $visitor->visit($this->command, $this->request, $param->setSentAs('test_3'), __FILE__);
$this->assertInternalType('array', $this->request->getPostFile('test_3')); $this->assertInternalType('array', $this->request->getPostFile('test_3'));
// Test with a PostFile // Test with a PostFile
$visitor->visit($this->command, $this->request, $param->setRename(null), new PostFile('baz', __FILE__)); $visitor->visit($this->command, $this->request, $param->setSentAs(null), new PostFile('baz', __FILE__));
$this->assertInternalType('array', $this->request->getPostFile('baz')); $this->assertInternalType('array', $this->request->getPostFile('baz'));
} }
} }

View File

@ -12,7 +12,7 @@ class QueryVisitorTest extends AbstractVisitorTestCase
public function testVisitsLocation() public function testVisitsLocation()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('query')->getParam('foo')->setRename('test'); $param = $this->getNestedCommand('query')->getParam('foo')->setSentAs('test');
$visitor->visit($this->command, $this->request, $param, '123'); $visitor->visit($this->command, $this->request, $param, '123');
$this->assertEquals('123', $this->request->getQuery()->get('test')); $this->assertEquals('123', $this->request->getQuery()->get('test'));
} }
@ -27,7 +27,7 @@ class QueryVisitorTest extends AbstractVisitorTestCase
$request = $command->prepare(); $request = $command->prepare();
$visitor = new Visitor(); $visitor = new Visitor();
$param = $this->getNestedCommand('query')->getParam('foo'); $param = $this->getNestedCommand('query')->getParam('foo');
$visitor->visit($command, $request, $param->setRename('Foo'), $command['foo']); $visitor->visit($command, $request, $param->setSentAs('Foo'), $command['foo']);
$visitor->after($command, $request); $visitor->after($command, $request);
$this->assertEquals( $this->assertEquals(
'?Foo[test][baz]=1&Foo[test][Jenga_Yall!]=HELLO&Foo[bar]=123', '?Foo[test][baz]=1&Foo[test][Jenga_Yall!]=HELLO&Foo[bar]=123',

View File

@ -50,7 +50,7 @@ class XmlVisitorTest extends AbstractVisitorTestCase
'location' => 'xml', 'location' => 'xml',
'items' => array( 'items' => array(
'type' => 'numeric', 'type' => 'numeric',
'rename' => 'Bar' 'sentAs' => 'Bar'
) )
) )
) )
@ -85,7 +85,7 @@ class XmlVisitorTest extends AbstractVisitorTestCase
'location' => 'xml', 'location' => 'xml',
'items' => array( 'items' => array(
'type' => 'object', 'type' => 'object',
'rename' => 'Bar', 'sentAs' => 'Bar',
'properties' => array('A' => array(), 'B' => array()) 'properties' => array('A' => array(), 'B' => array())
) )
) )
@ -210,7 +210,7 @@ class XmlVisitorTest extends AbstractVisitorTestCase
'required' => true, 'required' => true,
'type' => 'array', 'type' => 'array',
'min' => 1, 'min' => 1,
'items' => array('type' => 'string', 'rename' => 'Node') 'items' => array('type' => 'string', 'sentAs' => 'Node')
) )
) )
)); ));

View File

@ -14,7 +14,7 @@ class BodyVisitorTest extends AbstractResponseVisitorTest
public function testVisitsLocation() public function testVisitsLocation()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = new Parameter(array('location' => 'body', 'rename' => 'foo')); $param = new Parameter(array('location' => 'body', 'name' => 'foo'));
$visitor->visit($this->command, $this->response, $param, $this->value); $visitor->visit($this->command, $this->response, $param, $this->value);
$this->assertEquals('Foo', (string) $this->value['foo']); $this->assertEquals('Foo', (string) $this->value['foo']);
} }

View File

@ -14,8 +14,12 @@ class HeaderVisitorTest extends AbstractResponseVisitorTest
public function testVisitsLocation() public function testVisitsLocation()
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = new Parameter(array('location' => 'header', 'name' => 'Content-Type', 'rename' => 'type')); $param = new Parameter(array(
'location' => 'header',
'name' => 'ContentType',
'sentAs' => 'Content-Type'
));
$visitor->visit($this->command, $this->response, $param, $this->value); $visitor->visit($this->command, $this->response, $param, $this->value);
$this->assertEquals('text/plain', $this->value['type']); $this->assertEquals('text/plain', $this->value['ContentType']);
} }
} }

View File

@ -32,7 +32,7 @@ class JsonVisitorTest extends AbstractResponseVisitorTest
$visitor = new Visitor(); $visitor = new Visitor();
$param = new Parameter(array( $param = new Parameter(array(
'name' => 'foo', 'name' => 'foo',
'rename' => 'Baz', 'sentAs' => 'Baz',
'type' => 'string', 'type' => 'string',
)); ));
$this->value = array('Baz' => 'test'); $this->value = array('Baz' => 'test');

View File

@ -17,12 +17,12 @@ class XmlVisitorTest extends AbstractResponseVisitorTest
$param = new Parameter(array( $param = new Parameter(array(
'location' => 'xml', 'location' => 'xml',
'name' => 'foo', 'name' => 'foo',
'rename' => 'Bar' 'sentAs' => 'Bar'
)); ));
$value = array('foo' => 'test'); $value = array('Bar' => 'test');
$visitor->visit($this->command, $this->response, $param, $value); $visitor->visit($this->command, $this->response, $param, $value);
$this->assertArrayHasKey('Bar', $value); $this->assertArrayHasKey('foo', $value);
$this->assertEquals('test', $value['Bar']); $this->assertEquals('test', $value['foo']);
} }
public function testEnsuresRepeatedArraysAreInCorrectLocations() public function testEnsuresRepeatedArraysAreInCorrectLocations()
@ -31,7 +31,7 @@ class XmlVisitorTest extends AbstractResponseVisitorTest
$param = new Parameter(array( $param = new Parameter(array(
'location' => 'xml', 'location' => 'xml',
'name' => 'foo', 'name' => 'foo',
'rename' => 'Foo', 'sentAs' => 'Foo',
'type' => 'array', 'type' => 'array',
'items' => array( 'items' => array(
'type' => 'object', 'type' => 'object',
@ -43,13 +43,11 @@ class XmlVisitorTest extends AbstractResponseVisitorTest
) )
)); ));
$xml = new \SimpleXMLElement('<Test><foo><Bar>1</Bar><Baz>2</Baz></foo></Test>'); $xml = new \SimpleXMLElement('<Test><Foo><Bar>1</Bar><Baz>2</Baz></Foo></Test>');
$value = json_decode(json_encode($xml), true); $value = json_decode(json_encode($xml), true);
// Set a null value to ensure it is ignored
//$value['foo'][0]['Bam'] = null;
$visitor->visit($this->command, $this->response, $param, $value); $visitor->visit($this->command, $this->response, $param, $value);
$this->assertEquals(array( $this->assertEquals(array(
'Foo' => array( 'foo' => array(
array ( array (
'Bar' => '1', 'Bar' => '1',
'Baz' => '2' 'Baz' => '2'
@ -127,44 +125,44 @@ class XmlVisitorTest extends AbstractResponseVisitorTest
{ {
$visitor = new Visitor(); $visitor = new Visitor();
$param = new Parameter(array( $param = new Parameter(array(
'name' => 'instancesSet', 'name' => 'TerminatingInstances',
'type' => 'array', 'type' => 'array',
'location' => 'xml', 'location' => 'xml',
'rename' => 'TerminatingInstances', 'sentAs' => 'instancesSet',
'items' => array( 'items' => array(
'name' => 'item', 'name' => 'item',
'type' => 'object', 'type' => 'object',
'rename' => 'item', 'sentAs' => 'item',
'properties' => array( 'properties' => array(
'instanceId' => array( 'InstanceId' => array(
'type' => 'string', 'type' => 'string',
'rename' => 'InstanceId', 'sentAs' => 'instanceId',
), ),
'currentState' => array( 'CurrentState' => array(
'type' => 'object', 'type' => 'object',
'rename' => 'CurrentState', 'sentAs' => 'currentState',
'properties' => array( 'properties' => array(
'code' => array( 'Code' => array(
'type' => 'numeric', 'type' => 'numeric',
'rename' => 'Code', 'sentAs' => 'code',
), ),
'name' => array( 'Name' => array(
'type' => 'string', 'type' => 'string',
'rename' => 'Name', 'sentAs' => 'name',
), ),
), ),
), ),
'previousState' => array( 'PreviousState' => array(
'type' => 'object', 'type' => 'object',
'rename' => 'PreviousState', 'sentAs' => 'previousState',
'properties' => array( 'properties' => array(
'code' => array( 'Code' => array(
'type' => 'numeric', 'type' => 'numeric',
'rename' => 'Code', 'sentAs' => 'code',
), ),
'name' => array( 'Name' => array(
'type' => 'string', 'type' => 'string',
'rename' => 'Name', 'sentAs' => 'name',
), ),
), ),
), ),

View File

@ -90,9 +90,9 @@ class ParameterTest extends \Guzzle\Tests\GuzzleTestCase
public function testAllowsSimpleLocationValue() public function testAllowsSimpleLocationValue()
{ {
$p = new Parameter(array('name' => 'myname', 'location' => 'foo', 'rename' => 'Hello')); $p = new Parameter(array('name' => 'myname', 'location' => 'foo', 'sentAs' => 'Hello'));
$this->assertEquals('foo', $p->getLocation()); $this->assertEquals('foo', $p->getLocation());
$this->assertEquals('Hello', $p->getRename()); $this->assertEquals('Hello', $p->getSentAs());
} }
public function testParsesTypeValues() public function testParsesTypeValues()
@ -117,7 +117,7 @@ class ParameterTest extends \Guzzle\Tests\GuzzleTestCase
->setDescription('c') ->setDescription('c')
->setFilters(array('d')) ->setFilters(array('d'))
->setLocation('e') ->setLocation('e')
->setRename('f') ->setSentAs('f')
->setMaxLength(1) ->setMaxLength(1)
->setMinLength(1) ->setMinLength(1)
->setMinimum(2) ->setMinimum(2)
@ -136,7 +136,7 @@ class ParameterTest extends \Guzzle\Tests\GuzzleTestCase
$this->assertEquals('c', $p->getDescription()); $this->assertEquals('c', $p->getDescription());
$this->assertEquals(array('d', 'foo'), $p->getFilters()); $this->assertEquals(array('d', 'foo'), $p->getFilters());
$this->assertEquals('e', $p->getLocation()); $this->assertEquals('e', $p->getLocation());
$this->assertEquals('f', $p->getRename()); $this->assertEquals('f', $p->getSentAs());
$this->assertEquals(1, $p->getMaxLength()); $this->assertEquals(1, $p->getMaxLength());
$this->assertEquals(1, $p->getMinLength()); $this->assertEquals(1, $p->getMinLength());
$this->assertEquals(2, $p->getMaximum()); $this->assertEquals(2, $p->getMaximum());
@ -319,10 +319,10 @@ class ParameterTest extends \Guzzle\Tests\GuzzleTestCase
public function testHasKeyMethod() public function testHasKeyMethod()
{ {
$p = new Parameter(array('name' => 'foo', 'rename' => 'bar')); $p = new Parameter(array('name' => 'foo', 'sentAs' => 'bar'));
$this->assertEquals('bar', $p->getKey()); $this->assertEquals('bar', $p->getWireName());
$p->setRename(null); $p->setSentAs(null);
$this->assertEquals('foo', $p->getKey()); $this->assertEquals('foo', $p->getWireName());
} }
public function testIncludesNameInToArrayWhenItemsAttriubuteHasName() public function testIncludesNameInToArrayWhenItemsAttriubuteHasName()