Skip to content

Commit 89f200a

Browse files
committed
Fix tests for empty / null / false values when schema allows them
1 parent 4f04966 commit 89f200a

File tree

3 files changed

+7
-5
lines changed

3 files changed

+7
-5
lines changed

src/JsonSchema/Constraints/Object.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function validateElement($element, $objectDefinition = null, $path = null
3838
$definition = $this->getProperty($objectDefinition, $i);
3939

4040
//required property
41-
if ($this->getProperty($definition, 'required') && !$property) {
41+
if ($this->getProperty($definition, 'required') && $property instanceof Undefined) {
4242
$this->addError($path, "the property " . $i . " is required");
4343
}
4444

@@ -91,8 +91,10 @@ protected function getProperty($element, $property, $fallback = null)
9191
{
9292
if (is_array($element) /*$this->checkMode == self::CHECK_MODE_TYPE_CAST*/) {
9393
return array_key_exists($property, $element) ? $element[$property] : $fallback;
94-
} else {
95-
return isset($element->$property) ? $element->$property : $fallback;
94+
} else if (is_object($element)) {
95+
return property_exists($element, $property) ? $element->$property : $fallback;
9696
}
97+
98+
return $fallback;
9799
}
98100
}

src/JsonSchema/Constraints/Schema.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function check($element, $schema = null, $path = null, $i = null)
1818
if ($schema !== null) {
1919
// passed schema
2020
$this->checkUndefined($element, $schema, '', '');
21-
} elseif (isset($element->{$this->inlineSchemaProperty})) {
21+
} else if (property_exists($element, $this->inlineSchemaProperty)) {
2222
// inline schema
2323
$this->checkUndefined($element, $element->{$this->inlineSchemaProperty}, '', '');
2424
} else {

src/JsonSchema/Constraints/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function validateType($value, $type)
8484
case 'any' :
8585
return true;
8686
default:
87-
throw new \InvalidArgumentException((is_object($value) ? 'object' : $value) . ' is a invalid type for ' . $type);
87+
throw new \InvalidArgumentException((is_object($value) ? 'object' : $value) . ' is an invalid type for ' . $type);
8888
}
8989
}
9090
}

0 commit comments

Comments
 (0)