Skip to content

Commit 555d34c

Browse files
committed
Merge branch 'fix-issue-215'
* fix-issue-215: This patch fixes jsonrainbow#215 by ensuring that $value is not just an object but also not an instance of itself. Added a regression test. Rebased for jsonrainbow#224
2 parents f3380eb + a20e48e commit 555d34c

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null
166166
}
167167

168168
// Verify minimum and maximum number of properties
169-
if (is_object($value)) {
169+
if (is_object($value) && !($value instanceof UndefinedConstraint)) {
170170
if (isset($schema->minProperties)) {
171171
if (count(get_object_vars($value)) < $schema->minProperties) {
172172
$this->addError($path, "Must contain a minimum of " . $schema->minProperties . " properties", 'minProperties', array('minProperties' => $schema->minProperties,));

tests/JsonSchema/Tests/Constraints/MinItemsMaxItemsTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,30 @@ public function getValidTests()
6363
"value":{"type":"array","minItems":2,"maxItems":4}
6464
}
6565
}'
66+
),
67+
// Regression test for issue 215
68+
array(
69+
'{}',
70+
'{
71+
"type": "object",
72+
"additionalProperties": false,
73+
"properties": {
74+
"rooms": {
75+
"type": "object",
76+
"additionalProperties": false,
77+
"minProperties": 1,
78+
"maxProperties": 2,
79+
"properties": {
80+
"size_1": {
81+
"type": "number"
82+
},
83+
"size_2": {
84+
"type": "number"
85+
}
86+
}
87+
}
88+
}
89+
}'
6690
)
6791
);
6892
}

0 commit comments

Comments
 (0)