Skip to content

Commit

Permalink
Merge branch 'fix-issue-215'
Browse files Browse the repository at this point in the history
* fix-issue-215:
  Added a regression test for jsonrainbow#215.
  This patch fixes jsonrainbow#215 by ensuring that $value is not just an object but also not an instance of itself.
  • Loading branch information
rtucek committed Feb 1, 2016
2 parents f3380eb + 16fab63 commit 8d07d70
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null
}

// Verify minimum and maximum number of properties
if (is_object($value)) {
if (is_object($value) && !($value instanceof UndefinedConstraint)) {
if (isset($schema->minProperties)) {
if (count(get_object_vars($value)) < $schema->minProperties) {
$this->addError($path, "Must contain a minimum of " . $schema->minProperties . " properties", 'minProperties', array('minProperties' => $schema->minProperties,));
Expand Down
92 changes: 92 additions & 0 deletions tests/JsonSchema/Tests/Constraints/MinItemsMaxItemsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,98 @@ public function getValidTests()
"value":{"type":"array","minItems":2,"maxItems":4}
}
}'
),
// Regression test for issue 215
array(
'{
"campaign": 1,
"offset": 0,
"service_provider": 3,
"include_hotel": false,
"arrival": "2016-01-20",
"departure": "2016-01-27",
"session": "foobar",
"ip": "127.0.0.1",
"language_iso_code": "de",
"travellers": [
18,
18,
18
]
}',
'{
"type": "object",
"additionalProperties": false,
"required": [
"session",
"include_hotel",
"arrival",
"departure",
"ip",
"travellers",
"language_iso_code"
],
"properties": {
"session": {
"type": "string"
},
"campaign": {
"type": "integer"
},
"service_provider": {
"type": "integer"
},
"include_hotel": {
"type": "boolean"
},
"arrival": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
},
"departure": {
"type": "string",
"pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
},
"ip": {
"type": "string"
},
"offerId": {
"type": "integer",
"minimum": 1
},
"quiet": {
"type": "boolean"
},
"language_iso_code": {
"type": "string"
},
"travellers": {
"type": "array",
"minItems": 1,
"maxItems": 16,
"items": {
"type": "integer"
}
},
"rooms": {
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"maxProperties": 2,
"properties": {
"size_1": {
"type": "number"
},
"size_2": {
"type": "number"
}
}
},
"offset": {
"type": "integer"
}
}
}'
)
);
}
Expand Down

0 comments on commit 8d07d70

Please sign in to comment.