Skip to content

Commit

Permalink
Fix type-check problem with assoc tests
Browse files Browse the repository at this point in the history
  • Loading branch information
erayd committed Jan 19, 2017
1 parent a002a4d commit a7fa388
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/JsonSchema/Constraints/UndefinedConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions tests/Constraints/DefaultPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ 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);
} else {
$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));
Expand All @@ -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);
}
}

0 comments on commit a7fa388

Please sign in to comment.