diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index be932293..62a5dcef 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -66,8 +66,7 @@ public function validateTypes(&$value, $schema = null, JsonPointer $path, $i = n } // check object - if (TypeCheck\LooseTypeCheck::isObject($value)) { // Fixes failing assoc tests for default values - currently investigating - //if ($this->getTypeCheck()->isObject($value)) { // to find the root cause of this, noting all other assoc tests pass. + if ($this->getTypeCheck()->isObject($value)) { $this->checkObject( $value, isset($schema->properties) ? $this->factory->getSchemaStorage()->resolveRefSchema($schema->properties) : $schema, diff --git a/tests/Constraints/DefaultPropertiesTest.php b/tests/Constraints/DefaultPropertiesTest.php index fcebe893..7025070b 100644 --- a/tests/Constraints/DefaultPropertiesTest.php +++ b/tests/Constraints/DefaultPropertiesTest.php @@ -94,7 +94,7 @@ public function getValidTests() /** * @dataProvider getValidTests */ - public function testValidCases($input, $schema, $expectOutput = null) + public function testValidCases($input, $schema, $expectOutput = null, $validator = null) { if (is_string($input)) { $inputDecoded = json_decode($input); @@ -102,8 +102,10 @@ public function testValidCases($input, $schema, $expectOutput = null) $inputDecoded = $input; } - $checkMode = Constraint::CHECK_MODE_APPLY_DEFAULTS; - $validator = new Validator(new Factory(null, null, $checkMode)); + if ($validator === null) { + $checkMode = Constraint::CHECK_MODE_APPLY_DEFAULTS; + $validator = new Validator(new Factory(null, null, $checkMode)); + } $validator->coerce($inputDecoded, json_decode($schema)); $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true)); @@ -119,6 +121,9 @@ public function testValidCases($input, $schema, $expectOutput = null) public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null) { $input = json_decode($input, true); - self::testValidCases($input, $schema, $expectOutput); + + $checkMode = Constraint::CHECK_MODE_APPLY_DEFAULTS | Constraint::CHECK_MODE_TYPE_CAST; + $validator = new Validator(new Factory(null, null, $checkMode)); + self::testValidCases($input, $schema, $expectOutput, $validator); } }