Fix issues with uniqueItems in arrays. Use var_export() instead of print_r().

This commit is contained in:
Michael Chiocca 2013-05-07 07:10:04 -07:00
parent e09aa0b7a3
commit c230cad5f2
2 changed files with 57 additions and 1 deletions

View File

@ -36,7 +36,7 @@ class Collection extends Constraint
if (isset($schema->uniqueItems)) {
$unique = $value;
if (is_array($value) && count($value)) {
$unique = array_map(function($e) { return print_r($e, true); }, $value);
$unique = array_map(function($e) { return var_export($e, true); }, $value);
}
if (count(array_unique($unique)) != count($value)) {
$this->addError($path, "There are no duplicates allowed in the array");

View File

@ -34,6 +34,27 @@ class UniqueItemsTest extends BaseTestCase
"type": "array",
"uniqueItems": true
}'
),
array(
'[1.0, 1.00, 1]',
'{
"type": "array",
"uniqueItems": true
}'
),
array(
'[["foo"], ["foo"]]',
'{
"type": "array",
"uniqueItems": true
}'
),
array(
'[{}, [1], true, null, {}, 1]',
'{
"type": "array",
"uniqueItems": true
}'
)
);
}
@ -54,6 +75,41 @@ class UniqueItemsTest extends BaseTestCase
"type": "array",
"uniqueItems": true
}'
),
array(
'[1, true]',
'{
"type": "array",
"uniqueItems": true
}'
),
array(
'[0, false]',
'{
"type": "array",
"uniqueItems": true
}'
),
array(
'[{"foo": {"bar" : {"baz" : true}}}, {"foo": {"bar" : {"baz" : false}}}]',
'{
"type": "array",
"uniqueItems": true
}'
),
array(
'[["foo"], ["bar"]]',
'{
"type": "array",
"uniqueItems": true
}'
),
array(
'[{}, [1], true, null, 1]',
'{
"type": "array",
"uniqueItems": true
}'
)
);
}