Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the JSON Schema Test Suite to version 2.0.0 #582

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
],
"require": {
"php": ">=5.3.3",
"ext-json": "*",
"marc-mabe/php-enum":"^2.0 || ^3.0",
"icecave/parity": "1.0.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.2.20||~2.15.1",
"json-schema/JSON-Schema-Test-Suite": "1.2.0",
"json-schema/JSON-Schema-Test-Suite": "2.0.0",
"phpunit/phpunit": "^4.8.35"
},
"extra": {
Expand All @@ -56,11 +57,11 @@
"type": "package",
"package": {
"name": "json-schema/JSON-Schema-Test-Suite",
"version": "1.2.0",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/json-schema/JSON-Schema-Test-Suite",
"reference": "1.2.0"
"reference": "2.0.0"
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/JsonSchema/Constraints/ObjectConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ protected function &getProperty(&$element, $property, $fallback = null)
*/
protected function validateMinMaxConstraint($element, $objectDefinition, JsonPointer $path = null)
{
// minProperties and maxProperties constraints only applies on objects elements.
if (!is_object($element)) {
return;
}

// Verify minimum number of properties
if (isset($objectDefinition->minProperties) && !is_object($objectDefinition->minProperties)) {
if ($this->getTypeCheck()->propertyCount($element) < $objectDefinition->minProperties) {
Expand Down
51 changes: 41 additions & 10 deletions tests/Constraints/MinMaxPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,39 @@ public function getValidTests()
}
}'
),
// Ignore array.
array(
'{
"value": []
}',
'{
"properties": {
"value": {"minProperties": 1,"maxProperties": 2}
}
}'
),
// Ignore string.
array(
'{
"value": "foo"
}',
'{
"properties": {
"value": {"minProperties": 1,"maxProperties": 2}
}
}'
),
// Ignore anything that is non-object.
array(
'{
"value": 42
}',
'{
"properties": {
"value": {"minProperties": 1,"maxProperties": 2}
}
}'
),
);
}

Expand Down Expand Up @@ -123,16 +156,14 @@ public function getInvalidTests()
}
}'
),
array(
'{
"value": []
}',
'{
"properties": {
"value": {"minProperties": 1,"maxProperties": 2}
}
}'
),
);
}

/**
* {@inheritdoc}
*/
public function getInvalidForAssocTests()
{
return array();
}
}
13 changes: 10 additions & 3 deletions tests/Drafts/Draft4Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public function getInvalidForAssocTests()
$tests = parent::getInvalidForAssocTests();
unset(
$tests['type.json / object type matches objects / an array is not an object'],
$tests['type.json / array type matches arrays / an object is not an array']
$tests['type.json / array type matches arrays / an object is not an array'],
// Arrays must be ignored and in assoc case, these data are arrays and not objects.
$tests['maxProperties.json / maxProperties validation / too long is invalid'],
$tests['minProperties.json / minProperties validation / too short is invalid']
);

return $tests;
Expand All @@ -44,7 +47,9 @@ public function getValidForAssocTests()
$tests = parent::getValidForAssocTests();
unset(
$tests['type.json / object type matches objects / an array is not an object'],
$tests['type.json / array type matches arrays / an object is not an array']
$tests['type.json / array type matches arrays / an object is not an array'],
// Arrays must be ignored and in assoc case, these data are arrays and not objects.
$tests['required.json / required validation / ignores arrays']
);

return $tests;
Expand All @@ -58,10 +63,12 @@ protected function getSkippedTests()
return array(
// Optional
'bignum.json',
'ecmascript-regex.json',
'format.json',
'zeroTerminatedFloats.json',
// Required
'not.json' // only one test case failing
'not.json', // only one test case failing
'ref.json', // external references can not be found (localhost:1234)
);
}
}