diff --git a/src/JsonSchema/Constraints/CollectionConstraint.php b/src/JsonSchema/Constraints/CollectionConstraint.php index b43baced..93e0ab7b 100644 --- a/src/JsonSchema/Constraints/CollectionConstraint.php +++ b/src/JsonSchema/Constraints/CollectionConstraint.php @@ -76,7 +76,7 @@ protected function validateItems($value, $schema = null, $path = null, $i = null // Reset errors if needed if (isset($secondErrors) && count($secondErrors) < count($this->getErrors())) { $this->errors = $secondErrors; - } else if (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) { + } elseif (isset($secondErrors) && count($secondErrors) === count($this->getErrors())) { $this->errors = $initErrors; } } @@ -102,7 +102,7 @@ protected function validateItems($value, $schema = null, $path = null, $i = null } // Treat when we have more schema definitions than values, not for empty arrays - if(count($value) > 0) { + if (count($value) > 0) { for ($k = count($value); $k < count($schema->items); $k++) { $this->checkUndefined(new UndefinedConstraint(), $schema->items[$k], $path, $k); } diff --git a/src/JsonSchema/Constraints/Constraint.php b/src/JsonSchema/Constraints/Constraint.php index cb3ee809..fbf7f6ae 100644 --- a/src/JsonSchema/Constraints/Constraint.php +++ b/src/JsonSchema/Constraints/Constraint.php @@ -10,6 +10,7 @@ namespace JsonSchema\Constraints; use JsonSchema\Uri\UriRetriever; +use JsonSchema\Validator; /** * The Base Constraints, all Validators should extend this class @@ -49,8 +50,7 @@ public function __construct($checkMode = self::CHECK_MODE_NORMAL, UriRetriever $ */ public function getUriRetriever() { - if (is_null($this->uriRetriever)) - { + if (is_null($this->uriRetriever)) { $this->setUriRetriever(new UriRetriever); } @@ -63,7 +63,7 @@ public function getUriRetriever() public function getFactory() { if (!$this->factory) { - $this->factory = new Factory($this->getUriRetriever()); + $this->factory = new Factory($this->getUriRetriever(), $this->checkMode); } return $this->factory; @@ -288,4 +288,14 @@ protected function retrieveUri($uri) // TODO validate using schema return $jsonSchema; } + + /** + * Get the type check based on the set check mode. + * + * @return TypeCheck\TypeCheckInterface + */ + protected function getTypeCheck() + { + return $this->getFactory()->getTypeCheck(); + } } diff --git a/src/JsonSchema/Constraints/EnumConstraint.php b/src/JsonSchema/Constraints/EnumConstraint.php index 96b9e5a3..79ce3db3 100644 --- a/src/JsonSchema/Constraints/EnumConstraint.php +++ b/src/JsonSchema/Constraints/EnumConstraint.php @@ -8,6 +8,7 @@ */ namespace JsonSchema\Constraints; +use JsonSchema\Validator; /** * The EnumConstraint Constraints, validates an element against a given set of possibilities @@ -26,17 +27,23 @@ public function check($element, $schema = null, $path = null, $i = null) if ($element instanceof UndefinedConstraint && (!isset($schema->required) || !$schema->required)) { return; } + $type = gettype($element); foreach ($schema->enum as $enum) { - $type = gettype($element); + $enumType = gettype($enum); + if ($this->checkMode === self::CHECK_MODE_TYPE_CAST && $type == "array" && $enumType == "object") { + if ((object)$element == $enum) { + return; + } + } + if ($type === gettype($enum)) { if ($type == "object") { - if ($element == $enum) + if ($element == $enum) { return; - } else { - if ($element === $enum) - return; - + } + } elseif ($element === $enum) { + return; } } } diff --git a/src/JsonSchema/Constraints/Factory.php b/src/JsonSchema/Constraints/Factory.php index 8cd25c1f..7defbd68 100644 --- a/src/JsonSchema/Constraints/Factory.php +++ b/src/JsonSchema/Constraints/Factory.php @@ -11,7 +11,6 @@ use JsonSchema\Exception\InvalidArgumentException; use JsonSchema\Uri\UriRetriever; -use JsonSchema\Validator; /** * Factory for centralize constraint initialization. @@ -23,6 +22,16 @@ class Factory */ protected $uriRetriever; + /** + * @var int + */ + private $checkMode; + + /** + * @var TypeCheck\TypeCheckInterface[] + */ + private $typeCheck = array(); + /** * @var array $constraintMap */ @@ -43,13 +52,14 @@ class Factory /** * @param UriRetriever $uriRetriever */ - public function __construct(UriRetriever $uriRetriever = null) + public function __construct(UriRetriever $uriRetriever = null, $checkMode = Constraint::CHECK_MODE_NORMAL) { if (!$uriRetriever) { $uriRetriever = new UriRetriever(); } $this->uriRetriever = $uriRetriever; + $this->checkMode = $checkMode; } /** @@ -60,6 +70,19 @@ public function getUriRetriever() return $this->uriRetriever; } + public function getTypeCheck() + { + if (!isset($this->typeCheck[$this->checkMode])) { + if ($this->checkMode === Constraint::CHECK_MODE_TYPE_CAST) { + $this->typeCheck[Constraint::CHECK_MODE_TYPE_CAST] = new TypeCheck\LooseTypeCheck(); + } else { + $this->typeCheck[$this->checkMode] = new TypeCheck\StrictTypeCheck(); + } + } + + return $this->typeCheck[$this->checkMode]; + } + /** * @param string $name * @param string $class @@ -67,16 +90,16 @@ public function getUriRetriever() */ public function setConstraintClass($name, $class) { - // Ensure class exists - if (!class_exists($class)) { - throw new InvalidArgumentException('Unknown constraint ' . $name); - } - // Ensure class is appropriate - if (!in_array('JsonSchema\Constraints\ConstraintInterface', class_implements($class))) { - throw new InvalidArgumentException('Invalid class ' . $name); - } - $this->constraintMap[$name] = $class; - return $this; + // Ensure class exists + if (!class_exists($class)) { + throw new InvalidArgumentException('Unknown constraint ' . $name); + } + // Ensure class is appropriate + if (!in_array('JsonSchema\Constraints\ConstraintInterface', class_implements($class))) { + throw new InvalidArgumentException('Invalid class ' . $name); + } + $this->constraintMap[$name] = $class; + return $this; } /** @@ -89,7 +112,7 @@ public function setConstraintClass($name, $class) public function createInstanceFor($constraintName) { if (array_key_exists($constraintName, $this->constraintMap)) { - return new $this->constraintMap[$constraintName](Constraint::CHECK_MODE_NORMAL, $this->uriRetriever, $this); + return new $this->constraintMap[$constraintName]($this->checkMode, $this->uriRetriever, $this); } throw new InvalidArgumentException('Unknown constraint ' . $constraintName); } diff --git a/src/JsonSchema/Constraints/NumberConstraint.php b/src/JsonSchema/Constraints/NumberConstraint.php index 35560c13..7b359921 100644 --- a/src/JsonSchema/Constraints/NumberConstraint.php +++ b/src/JsonSchema/Constraints/NumberConstraint.php @@ -27,13 +27,13 @@ public function check($element, $schema = null, $path = null, $i = null) if (isset($schema->minimum)) { if ($schema->exclusiveMinimum && $element <= $schema->minimum) { $this->addError($path, "Must have a minimum value of " . $schema->minimum, 'exclusiveMinimum', array('minimum' => $schema->minimum,)); - } else if ($element < $schema->minimum) { + } elseif ($element < $schema->minimum) { $this->addError($path, "Must have a minimum value of " . $schema->minimum, 'minimum', array('minimum' => $schema->minimum,)); } } else { $this->addError($path, "Use of exclusiveMinimum requires presence of minimum", 'missingMinimum'); } - } else if (isset($schema->minimum) && $element < $schema->minimum) { + } elseif (isset($schema->minimum) && $element < $schema->minimum) { $this->addError($path, "Must have a minimum value of " . $schema->minimum, 'minimum', array('minimum' => $schema->minimum,)); } @@ -42,13 +42,13 @@ public function check($element, $schema = null, $path = null, $i = null) if (isset($schema->maximum)) { if ($schema->exclusiveMaximum && $element >= $schema->maximum) { $this->addError($path, "Must have a maximum value of " . $schema->maximum, 'exclusiveMaximum', array('maximum' => $schema->maximum,)); - } else if ($element > $schema->maximum) { + } elseif ($element > $schema->maximum) { $this->addError($path, "Must have a maximum value of " . $schema->maximum, 'maximum', array('maximum' => $schema->maximum,)); } } else { $this->addError($path, "Use of exclusiveMaximum requires presence of maximum", 'missingMaximum'); } - } else if (isset($schema->maximum) && $element > $schema->maximum) { + } elseif (isset($schema->maximum) && $element > $schema->maximum) { $this->addError($path, "Must have a maximum value of " . $schema->maximum, 'maximum', array('maximum' => $schema->maximum,)); } diff --git a/src/JsonSchema/Constraints/ObjectConstraint.php b/src/JsonSchema/Constraints/ObjectConstraint.php index f40e1202..73af5177 100644 --- a/src/JsonSchema/Constraints/ObjectConstraint.php +++ b/src/JsonSchema/Constraints/ObjectConstraint.php @@ -20,7 +20,7 @@ class ObjectConstraint extends Constraint /** * {@inheritDoc} */ - function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null) + public function check($element, $definition = null, $path = null, $additionalProp = null, $patternProperties = null) { if ($element instanceof UndefinedConstraint) { return; @@ -161,13 +161,13 @@ protected function getProperty($element, $property, $fallback = null) protected function validateMinMaxConstraint($element, $objectDefinition, $path) { // Verify minimum number of properties if (isset($objectDefinition->minProperties) && !is_object($objectDefinition->minProperties)) { - if (count(get_object_vars($element)) < $objectDefinition->minProperties) { + if ($this->getTypeCheck()->propertyCount($element) < $objectDefinition->minProperties) { $this->addError($path, "Must contain a minimum of " . $objectDefinition->minProperties . " properties", 'minProperties', array('minProperties' => $objectDefinition->minProperties,)); } } // Verify maximum number of properties if (isset($objectDefinition->maxProperties) && !is_object($objectDefinition->maxProperties)) { - if (count(get_object_vars($element)) > $objectDefinition->maxProperties) { + if ($this->getTypeCheck()->propertyCount($element) > $objectDefinition->maxProperties) { $this->addError($path, "Must contain no more than " . $objectDefinition->maxProperties . " properties", 'maxProperties', array('maxProperties' => $objectDefinition->maxProperties,)); } } diff --git a/src/JsonSchema/Constraints/SchemaConstraint.php b/src/JsonSchema/Constraints/SchemaConstraint.php index b856a114..ffd4757b 100644 --- a/src/JsonSchema/Constraints/SchemaConstraint.php +++ b/src/JsonSchema/Constraints/SchemaConstraint.php @@ -27,11 +27,16 @@ public function check($element, $schema = null, $path = null, $i = null) if ($schema !== null) { // passed schema $this->checkUndefined($element, $schema, '', ''); - } elseif (property_exists($element, $this->inlineSchemaProperty)) { + } elseif ($this->getTypeCheck()->propertyExists($element, $this->inlineSchemaProperty)) { + $inlineSchema = $this->getTypeCheck()->propertyGet($element, $this->inlineSchemaProperty); + if (is_array($inlineSchema)) { + $inlineSchema = json_decode(json_encode($inlineSchema)); + } + // inline schema - $this->checkUndefined($element, $element->{$this->inlineSchemaProperty}, '', ''); + $this->checkUndefined($element, $inlineSchema, '', ''); } else { throw new InvalidArgumentException('no schema found to verify against'); } } -} \ No newline at end of file +} diff --git a/src/JsonSchema/Constraints/TypeCheck/LooseTypeCheck.php b/src/JsonSchema/Constraints/TypeCheck/LooseTypeCheck.php new file mode 100644 index 00000000..7499c2e3 --- /dev/null +++ b/src/JsonSchema/Constraints/TypeCheck/LooseTypeCheck.php @@ -0,0 +1,59 @@ +{$property}; + } + + return $value[$property]; + } + + public static function propertyExists($value, $property) + { + if (is_object($value)) { + return property_exists($value, $property); + } + + return array_key_exists($property, $value); + } + + public static function propertyCount($value) + { + if (is_object($value)) { + return count(get_object_vars($value)); + } + + return count($value); + } + + /** + * Check if the provided array is associative or not + * + * @param array $arr + * + * @return bool + */ + private static function isAssociativeArray($arr) + { + return (array_keys($arr) !== range(0, count($arr) - 1)); + } +} diff --git a/src/JsonSchema/Constraints/TypeCheck/StrictTypeCheck.php b/src/JsonSchema/Constraints/TypeCheck/StrictTypeCheck.php new file mode 100644 index 00000000..73bbc383 --- /dev/null +++ b/src/JsonSchema/Constraints/TypeCheck/StrictTypeCheck.php @@ -0,0 +1,31 @@ +{$property}; + } + + public static function propertyExists($value, $property) + { + return property_exists($value, $property); + } + + public static function propertyCount($value) + { + return count(get_object_vars($value)); + } +} diff --git a/src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php b/src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php new file mode 100644 index 00000000..5fd68acd --- /dev/null +++ b/src/JsonSchema/Constraints/TypeCheck/TypeCheckInterface.php @@ -0,0 +1,16 @@ +checkMode) ? is_array($value) : is_object($value); + return $this->getTypeCheck()->isObject($value); } if ('array' === $type) { - return is_array($value); + return $this->getTypeCheck()->isArray($value); } if ('string' === $type) { diff --git a/src/JsonSchema/Constraints/UndefinedConstraint.php b/src/JsonSchema/Constraints/UndefinedConstraint.php index c90cccf4..63947199 100644 --- a/src/JsonSchema/Constraints/UndefinedConstraint.php +++ b/src/JsonSchema/Constraints/UndefinedConstraint.php @@ -9,7 +9,6 @@ namespace JsonSchema\Constraints; -use JsonSchema\Exception\InvalidArgumentException; use JsonSchema\Uri\UriResolver; /** @@ -53,12 +52,12 @@ public function check($value, $schema = null, $path = null, $i = null) public function validateTypes($value, $schema = null, $path = null, $i = null) { // check array - if (is_array($value)) { + if ($this->getTypeCheck()->isArray($value)) { $this->checkArray($value, $schema, $path, $i); } // check object - if (is_object($value)) { + if ($this->getTypeCheck()->isObject($value)) { $this->checkObject( $value, isset($schema->properties) ? $schema->properties : $schema, @@ -109,17 +108,17 @@ protected function validateCommonProperties($value, $schema = null, $path = null } // Verify required values - if (is_object($value)) { - if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required) ) { + if ($this->getTypeCheck()->isObject($value)) { + if (!($value instanceof UndefinedConstraint) && isset($schema->required) && is_array($schema->required)) { // Draft 4 - Required is an array of strings - e.g. "required": ["foo", ...] foreach ($schema->required as $required) { - if (!property_exists($value, $required)) { + if (!$this->getTypeCheck()->propertyExists($value, $required)) { $this->addError((!$path) ? $required : "$path.$required", "The property " . $required . " is required", 'required'); } } - } else if (isset($schema->required) && !is_array($schema->required)) { + } elseif (isset($schema->required) && !is_array($schema->required)) { // Draft 3 - Required attribute - e.g. "foo": {"type": "string", "required": true} - if ( $schema->required && $value instanceof UndefinedConstraint) { + if ($schema->required && $value instanceof UndefinedConstraint) { $this->addError($path, "Is missing and it is required", 'required'); } } @@ -159,7 +158,7 @@ protected function validateCommonProperties($value, $schema = null, $path = null } // Verify that dependencies are met - if (is_object($value) && isset($schema->dependencies)) { + if (isset($schema->dependencies) && $this->getTypeCheck()->isObject($value)) { $this->validateDependencies($value, $schema->dependencies, $path); } } @@ -249,20 +248,20 @@ protected function validateOfProperties($value, $schema, $path, $i = "") protected function validateDependencies($value, $dependencies, $path, $i = "") { foreach ($dependencies as $key => $dependency) { - if (property_exists($value, $key)) { + if ($this->getTypeCheck()->propertyExists($value, $key)) { if (is_string($dependency)) { // Draft 3 string is allowed - e.g. "dependencies": {"bar": "foo"} - if (!property_exists($value, $dependency)) { + if (!$this->getTypeCheck()->propertyExists($value, $dependency)) { $this->addError($path, "$key depends on $dependency and $dependency is missing", 'dependencies'); } - } else if (is_array($dependency)) { + } elseif (is_array($dependency)) { // Draft 4 must be an array - e.g. "dependencies": {"bar": ["foo"]} foreach ($dependency as $d) { - if (!property_exists($value, $d)) { + if (!$this->getTypeCheck()->propertyExists($value, $d)) { $this->addError($path, "$key depends on $d and $d is missing", 'dependencies'); } } - } else if (is_object($dependency)) { + } elseif (is_object($dependency)) { // Schema - e.g. "dependencies": {"bar": {"properties": {"foo": {...}}}} $this->checkUndefined($value, $dependency, $path, $i); } diff --git a/tests/Constraints/AdditionalPropertiesTest.php b/tests/Constraints/AdditionalPropertiesTest.php index c56f0ce5..24254d0b 100644 --- a/tests/Constraints/AdditionalPropertiesTest.php +++ b/tests/Constraints/AdditionalPropertiesTest.php @@ -9,8 +9,6 @@ namespace JsonSchema\Tests\Constraints; -use JsonSchema\Validator; - class AdditionalPropertiesTest extends BaseTestCase { public function getInvalidTests() @@ -52,8 +50,7 @@ public function getInvalidTests() "prop":{"type":"string"} }, "additionalProperties": false - }', - Validator::CHECK_MODE_TYPE_CAST + }' ), array( '{ @@ -79,8 +76,7 @@ public function getInvalidTests() "prop":{"type":"string"} }, "additionalProperties": {"type":"string"} - }', - Validator::CHECK_MODE_TYPE_CAST + }' ), array( '{ @@ -132,8 +128,7 @@ public function getValidTests() "properties":{ "prop":{"type":"string"} } - }', - Validator::CHECK_MODE_TYPE_CAST + }' ), array( '{ diff --git a/tests/Constraints/BaseTestCase.php b/tests/Constraints/BaseTestCase.php index 27cb6b09..52bcd456 100644 --- a/tests/Constraints/BaseTestCase.php +++ b/tests/Constraints/BaseTestCase.php @@ -9,6 +9,7 @@ namespace JsonSchema\Tests\Constraints; +use JsonSchema\Constraints\Constraint; use JsonSchema\RefResolver; use JsonSchema\Uri\UriResolver; use JsonSchema\Validator; @@ -28,8 +29,10 @@ abstract class BaseTestCase extends \PHPUnit_Framework_TestCase /** * @dataProvider getInvalidTests */ - public function testInvalidCases($input, $jsonSchema, $checkMode = Validator::CHECK_MODE_NORMAL, $errors = array()) + public function testInvalidCases($input, $jsonSchema, $checkMode = Constraint::CHECK_MODE_NORMAL, $errors = array()) { + $checkMode = $checkMode === null ? Constraint::CHECK_MODE_NORMAL : $checkMode; + $schema = json_decode($jsonSchema); if (is_object($schema)) { $schema = $this->resolveSchema($schema); @@ -46,10 +49,36 @@ public function testInvalidCases($input, $jsonSchema, $checkMode = Validator::CH $this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true)); } + /** + * @dataProvider getInvalidForAssocTests + */ + public function testInvalidCasesUsingAssoc($input, $jsonSchema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST, $errors = array()) + { + $checkMode = $checkMode === null ? Constraint::CHECK_MODE_TYPE_CAST : $checkMode; + if ($checkMode !== Constraint::CHECK_MODE_TYPE_CAST) { + $this->markTestSkipped('Test indicates that it is not for "CHECK_MODE_TYPE_CAST"'); + } + + $schema = json_decode($jsonSchema); + if (is_object($schema)) { + $schema = $this->resolveSchema($schema); + } + + $value = json_decode($input, true); + + $validator = new Validator($checkMode); + $validator->check($value, $schema); + + if (array() !== $errors) { + $this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(), true)); + } + $this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true)); + } + /** * @dataProvider getValidTests */ - public function testValidCases($input, $schema, $checkMode = Validator::CHECK_MODE_NORMAL) + public function testValidCases($input, $schema, $checkMode = Constraint::CHECK_MODE_NORMAL) { $schema = json_decode($schema); if (is_object($schema)) { @@ -63,16 +92,53 @@ public function testValidCases($input, $schema, $checkMode = Validator::CHECK_MO $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true)); } + /** + * @dataProvider getValidForAssocTests + */ + public function testValidCasesUsingAssoc($input, $schema, $checkMode = Constraint::CHECK_MODE_TYPE_CAST) + { + if ($checkMode !== Constraint::CHECK_MODE_TYPE_CAST) { + $this->markTestSkipped('Test indicates that it is not for "CHECK_MODE_TYPE_CAST"'); + } + + $schema = json_decode($schema); + if (is_object($schema)) { + $schema = $this->resolveSchema($schema); + } + + $value = json_decode($input, true); + $validator = new Validator($checkMode); + + $validator->check($value, $schema); + $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true)); + } + /** * @return array[] */ abstract public function getValidTests(); + /** + * @return array[] + */ + public function getValidForAssocTests() + { + return $this->getValidTests(); + } + /** * @return array[] */ abstract public function getInvalidTests(); + /** + * @return array[] + */ + public function getInvalidForAssocTests() + { + return $this->getInvalidTests(); + } + /** * @param object $schema * @return object diff --git a/tests/Constraints/OfPropertiesTest.php b/tests/Constraints/OfPropertiesTest.php index 65d8373d..34c8cbff 100644 --- a/tests/Constraints/OfPropertiesTest.php +++ b/tests/Constraints/OfPropertiesTest.php @@ -7,8 +7,6 @@ */ namespace JsonSchema\Tests\Constraints; -use JsonSchema\Validator; - /** * Class OfPropertiesTest */ @@ -71,7 +69,7 @@ public function getInvalidTests() }, "required": ["prop1"] }', - Validator::CHECK_MODE_NORMAL, + null, array( array( "property" => "prop2", diff --git a/tests/Constraints/RequiredPropertyTest.php b/tests/Constraints/RequiredPropertyTest.php index fd3b4193..4938ec2e 100644 --- a/tests/Constraints/RequiredPropertyTest.php +++ b/tests/Constraints/RequiredPropertyTest.php @@ -9,6 +9,7 @@ namespace JsonSchema\Tests\Constraints; +use JsonSchema\Constraints\Constraint; use JsonSchema\Constraints\UndefinedConstraint; class RequiredPropertyTest extends BaseTestCase @@ -229,7 +230,8 @@ public function getInvalidTests() "properties": { "array":{"type":"array", "required": true} } - }' + }', + Constraint::CHECK_MODE_NORMAL ), array( '{ diff --git a/tests/Drafts/BaseDraftTestCase.php b/tests/Drafts/BaseDraftTestCase.php index 59dcc972..6e9e06f0 100644 --- a/tests/Drafts/BaseDraftTestCase.php +++ b/tests/Drafts/BaseDraftTestCase.php @@ -21,17 +21,19 @@ private function setUpTests($isValid) foreach ($filePaths as $path) { foreach (glob($path . '/*.json') as $file) { $filename = basename($file); - if (!in_array($filename, $skippedTests)) { - $suites = json_decode(file_get_contents($file)); - foreach ($suites as $suite) { - $suiteDescription = $suite->description; - foreach ($suite->tests as $test) { - $testCaseDescription = $test->description; - if ($isValid === $test->valid) { - $tests[ - $this->createDataSetPath($filename, $suiteDescription, $testCaseDescription) - ] = array(json_encode($test->data), json_encode($suite->schema)); - } + if (in_array($filename, $skippedTests)) { + continue; + } + + $suites = json_decode(file_get_contents($file)); + foreach ($suites as $suite) { + $suiteDescription = $suite->description; + foreach ($suite->tests as $test) { + $testCaseDescription = $test->description; + if ($isValid === $test->valid) { + $tests[ + $this->createDataSetPath($filename, $suiteDescription, $testCaseDescription) + ] = array(json_encode($test->data), json_encode($suite->schema)); } } } diff --git a/tests/Drafts/Draft3Test.php b/tests/Drafts/Draft3Test.php index ee10f66a..72ec0ebd 100644 --- a/tests/Drafts/Draft3Test.php +++ b/tests/Drafts/Draft3Test.php @@ -8,6 +8,7 @@ */ namespace JsonSchema\Tests\Drafts; +use JsonSchema\Constraints\Constraint; /** * @package JsonSchema\Tests\Drafts @@ -25,6 +26,28 @@ protected function getFilePaths() ); } + public function getInvalidForAssocTests() + { + $tests = parent::getInvalidForAssocTests(); + unset( + $tests['type.json / object type matches objects / an array is not an object'], + $tests['type.json / array type matches arrays / an object is not an array'] + ); + + return $tests; + } + + public function getValidForAssocTests() + { + $tests = parent::getValidForAssocTests(); + unset( + $tests['type.json / object type matches objects / an array is not an object'], + $tests['type.json / array type matches arrays / an object is not an array'] + ); + + return $tests; + } + /** * {@inheritdoc} */ diff --git a/tests/Drafts/Draft4Test.php b/tests/Drafts/Draft4Test.php index 320cf61c..a4508b0f 100644 --- a/tests/Drafts/Draft4Test.php +++ b/tests/Drafts/Draft4Test.php @@ -25,6 +25,28 @@ protected function getFilePaths() ); } + public function getInvalidForAssocTests() + { + $tests = parent::getInvalidForAssocTests(); + unset( + $tests['type.json / object type matches objects / an array is not an object'], + $tests['type.json / array type matches arrays / an object is not an array'] + ); + + return $tests; + } + + public function getValidForAssocTests() + { + $tests = parent::getValidForAssocTests(); + unset( + $tests['type.json / object type matches objects / an array is not an object'], + $tests['type.json / array type matches arrays / an object is not an array'] + ); + + return $tests; + } + /** * {@inheritdoc} */