Skip to content

Commit a7fa388

Browse files
committed
Fix type-check problem with assoc tests
1 parent a002a4d commit a7fa388

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ public function validateTypes(&$value, $schema = null, JsonPointer $path, $i = n
6666
}
6767

6868
// check object
69-
if (TypeCheck\LooseTypeCheck::isObject($value)) { // Fixes failing assoc tests for default values - currently investigating
70-
//if ($this->getTypeCheck()->isObject($value)) { // to find the root cause of this, noting all other assoc tests pass.
69+
if ($this->getTypeCheck()->isObject($value)) {
7170
$this->checkObject(
7271
$value,
7372
isset($schema->properties) ? $this->factory->getSchemaStorage()->resolveRefSchema($schema->properties) : $schema,

tests/Constraints/DefaultPropertiesTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,18 @@ public function getValidTests()
9494
/**
9595
* @dataProvider getValidTests
9696
*/
97-
public function testValidCases($input, $schema, $expectOutput = null)
97+
public function testValidCases($input, $schema, $expectOutput = null, $validator = null)
9898
{
9999
if (is_string($input)) {
100100
$inputDecoded = json_decode($input);
101101
} else {
102102
$inputDecoded = $input;
103103
}
104104

105-
$checkMode = Constraint::CHECK_MODE_APPLY_DEFAULTS;
106-
$validator = new Validator(new Factory(null, null, $checkMode));
105+
if ($validator === null) {
106+
$checkMode = Constraint::CHECK_MODE_APPLY_DEFAULTS;
107+
$validator = new Validator(new Factory(null, null, $checkMode));
108+
}
107109
$validator->coerce($inputDecoded, json_decode($schema));
108110

109111
$this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
@@ -119,6 +121,9 @@ public function testValidCases($input, $schema, $expectOutput = null)
119121
public function testValidCasesUsingAssoc($input, $schema, $expectOutput = null)
120122
{
121123
$input = json_decode($input, true);
122-
self::testValidCases($input, $schema, $expectOutput);
124+
125+
$checkMode = Constraint::CHECK_MODE_APPLY_DEFAULTS | Constraint::CHECK_MODE_TYPE_CAST;
126+
$validator = new Validator(new Factory(null, null, $checkMode));
127+
self::testValidCases($input, $schema, $expectOutput, $validator);
123128
}
124129
}

0 commit comments

Comments
 (0)