Skip to content

Commit

Permalink
Sync compliance tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jeskew committed Oct 29, 2015
1 parent a9eca95 commit eb72fec
Show file tree
Hide file tree
Showing 12 changed files with 556 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/Api/Parser/JsonParser.php
Expand Up @@ -11,6 +11,10 @@ class JsonParser
{
public function parse(Shape $shape, $value)
{
if ($value === null) {
return $value;
}

switch ($shape['type']) {
case 'structure':
$target = [];
Expand Down
7 changes: 3 additions & 4 deletions src/Api/Serializer/JsonBody.php
Expand Up @@ -53,10 +53,9 @@ private function format(Shape $shape, $value)
$data = [];
foreach ($value as $k => $v) {
if ($v !== null && $shape->hasMember($k)) {
$data[$shape['locationName'] ?: $k] = $this->format(
$shape->getMember($k),
$v
);
$valueShape = $shape->getMember($k);
$data[$valueShape['locationName'] ?: $k]
= $this->format($valueShape, $v);
}
}
return $data;
Expand Down
3 changes: 2 additions & 1 deletion src/Api/Serializer/QueryParamBuilder.php
Expand Up @@ -96,7 +96,8 @@ protected function format_list(
$items = $shape->getMember();

if (!$this->isFlat($shape)) {
$prefix .= '.member';
$locationName = $shape->getMember()['locationName'] ?: 'member';
$prefix .= ".$locationName";
} elseif ($name = $this->queryName($items)) {
$parts = explode('.', $prefix);
$parts[count($parts) - 1] = $name;
Expand Down
8 changes: 5 additions & 3 deletions tests/Api/Parser/ComplianceTest.php
Expand Up @@ -82,9 +82,11 @@ private function fixTimestamps(&$data, Shape $shape)
{
switch (get_class($shape)) {
case 'Aws\Api\StructureShape':
foreach ($data as $key => &$value) {
if ($shape->hasMember($key)) {
$this->fixTimestamps($value, $shape->getMember($key));
if ($data) {
foreach ($data as $key => &$value) {
if ($shape->hasMember($key)) {
$this->fixTimestamps($value, $shape->getMember($key));
}
}
}
break;
Expand Down
7 changes: 4 additions & 3 deletions tests/Api/Serializer/ComplianceTest.php
Expand Up @@ -45,7 +45,7 @@ function () { return []; }
$file . ': ' . $suite['description'],
$description,
$case['given']['name'],
$case['params'],
isset($case['params']) ? $case['params'] : [],
$case['serialized']
];
}
Expand Down Expand Up @@ -77,7 +77,8 @@ public function testPassesComplianceTest(
'endpoint' => $ep,
'error_parser' => Service::createErrorParser($service->getProtocol()),
'serializer' => Service::createSerializer($service, $ep),
'version' => 'latest'
'version' => 'latest',
'validate' => false,
]);

$command = $client->getCommand($name, $args);
Expand All @@ -94,7 +95,7 @@ public function testPassesComplianceTest(
break;
case 'rest-xml':
// Normalize XML data.
if ($serialized['body'] && strpos($serialized['body'], '</')) {
if ($serialized['body'] && preg_match('/(\<\/|\/\>)/', $serialized['body'])) {
$serialized['body'] = str_replace(
' />',
'/>',
Expand Down
177 changes: 177 additions & 0 deletions tests/Api/test_cases/protocols/input/query.json
Expand Up @@ -14,11 +14,17 @@
},
"Bar": {
"shape": "StringType"
},
"Baz": {
"shape": "BooleanType"
}
}
},
"StringType": {
"type": "string"
},
"BooleanType": {
"type": "boolean"
}
},
"cases": [
Expand All @@ -37,6 +43,36 @@
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&Foo=val1&Bar=val2"
}
},
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"Baz": true
},
"serialized": {
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&Baz=true"
}
},
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"Baz": false
},
"serialized": {
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&Baz=false"
}
}
]
},
Expand Down Expand Up @@ -131,6 +167,21 @@
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&ListArg.member.1=foo&ListArg.member.2=bar&ListArg.member.3=baz"
}
},
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"ListArg": []
},
"serialized": {
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&ListArg="
}
}
]
},
Expand All @@ -149,6 +200,9 @@
},
"ListArg": {
"shape": "ListType"
},
"NamedListArg": {
"shape": "NamedListType"
}
}
},
Expand All @@ -159,6 +213,14 @@
},
"flattened": true
},
"NamedListType": {
"type": "list",
"member": {
"shape": "StringType",
"locationName": "Foo"
},
"flattened": true
},
"StringType": {
"type": "string"
}
Expand All @@ -183,6 +245,121 @@
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&ScalarArg=foo&ListArg.1=a&ListArg.2=b&ListArg.3=c"
}
},
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"NamedListArg": [
"a"
]
},
"serialized": {
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&Foo.1=a"
}
}
]
},
{
"description": "Serialize flattened map type",
"metadata": {
"protocol": "query",
"apiVersion": "2014-01-01"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"MapArg": {
"shape": "StringMap"
}
}
},
"StringMap": {
"type": "map",
"key": {
"shape": "StringType"
},
"value": {
"shape": "StringType"
},
"flattened": true
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"MapArg": {
"key1": "val1",
"key2": "val2"
}
},
"serialized": {
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&MapArg.1.key=key1&MapArg.1.value=val1&MapArg.2.key=key2&MapArg.2.value=val2"
}
}
]
},
{
"description": "Non flattened list with LocationName",
"metadata": {
"protocol": "query",
"apiVersion": "2014-01-01"
},
"shapes": {
"InputShape": {
"type": "structure",
"members": {
"ListArg": {
"shape": "ListType"
}
}
},
"ListType": {
"type": "list",
"member": {
"shape": "StringType",
"locationName": "item"
}
},
"StringType": {
"type": "string"
}
},
"cases": [
{
"given": {
"input": {
"shape": "InputShape"
},
"name": "OperationName"
},
"params": {
"ListArg": [
"a",
"b",
"c"
]
},
"serialized": {
"uri": "/",
"body": "Action=OperationName&Version=2014-01-01&ListArg.item.1=a&ListArg.item.2=b&ListArg.item.3=c"
}
}
]
},
Expand Down

0 comments on commit eb72fec

Please sign in to comment.