From 284f3e53aa2938be7a4cdb0c5214e43f4b38181c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=B6ller?= Date: Sat, 30 Dec 2017 19:03:22 +0100 Subject: [PATCH] Fix: Mark check() and coerce() as deprecated --- bin/validate-json | 2 +- demo/demo.php | 2 +- src/JsonSchema/Validator.php | 4 ++++ tests/Constraints/LongArraysTest.php | 6 +++--- tests/Constraints/PointerTest.php | 2 +- tests/Constraints/SelfDefinedSchemaTest.php | 7 ++++++- tests/Uri/UriRetrieverTest.php | 8 ++++---- tests/ValidatorTest.php | 4 ++-- 8 files changed, 22 insertions(+), 13 deletions(-) diff --git a/bin/validate-json b/bin/validate-json index 5de011ce..94c4a341 100755 --- a/bin/validate-json +++ b/bin/validate-json @@ -217,7 +217,7 @@ if (isset($arOptions['--dump-schema'])) { try { $validator = new JsonSchema\Validator(); - $validator->check($data, $schema); + $validator->validate($data, $schema); if ($validator->isValid()) { if(isset($arOptions['--verbose'])) { diff --git a/demo/demo.php b/demo/demo.php index 98b518a7..3f824901 100644 --- a/demo/demo.php +++ b/demo/demo.php @@ -6,7 +6,7 @@ // Validate $validator = new JsonSchema\Validator(); -$validator->check($data, (object) array('$ref' => 'file://' . realpath('schema.json'))); +$validator->validate($data, (object) array('$ref' => 'file://' . realpath('schema.json'))); if ($validator->isValid()) { echo "The supplied JSON validates against the schema.\n"; diff --git a/src/JsonSchema/Validator.php b/src/JsonSchema/Validator.php index eb1c18d2..01ef0701 100644 --- a/src/JsonSchema/Validator.php +++ b/src/JsonSchema/Validator.php @@ -74,6 +74,8 @@ public function validate(&$value, $schema = null, $checkMode = null) /** * Alias to validate(), to maintain backwards-compatibility with the previous API + * + * @deprecated */ public function check($value, $schema) { @@ -82,6 +84,8 @@ public function check($value, $schema) /** * Alias to validate(), to maintain backwards-compatibility with the previous API + * + * @deprecated */ public function coerce(&$value, $schema) { diff --git a/tests/Constraints/LongArraysTest.php b/tests/Constraints/LongArraysTest.php index 2757b964..8613a652 100644 --- a/tests/Constraints/LongArraysTest.php +++ b/tests/Constraints/LongArraysTest.php @@ -41,7 +41,7 @@ public function testLongStringArray() $validator = new Validator(new Factory($schemaStorage)); $checkValue = json_decode($input); - $validator->check($checkValue, $schema); + $validator->validate($checkValue, $schema); $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true)); } @@ -69,7 +69,7 @@ public function testLongNumberArray() $validator = new Validator(new Factory($schemaStorage)); $checkValue = json_decode($input); - $validator->check($checkValue, $schema); + $validator->validate($checkValue, $schema); $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true)); } @@ -97,7 +97,7 @@ public function testLongIntegerArray() $validator = new Validator(new Factory($schemaStorage)); $checkValue = json_decode($input); - $validator->check($checkValue, $schema); + $validator->validate($checkValue, $schema); $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true)); } diff --git a/tests/Constraints/PointerTest.php b/tests/Constraints/PointerTest.php index 85d4484a..ef52e44b 100644 --- a/tests/Constraints/PointerTest.php +++ b/tests/Constraints/PointerTest.php @@ -83,7 +83,7 @@ public function testVariousPointers() $validator = new Validator(); $checkValue = json_decode(json_encode($value)); - $validator->check($checkValue, json_decode(json_encode($schema))); + $validator->validate($checkValue, json_decode(json_encode($schema))); $this->assertEquals( array( diff --git a/tests/Constraints/SelfDefinedSchemaTest.php b/tests/Constraints/SelfDefinedSchemaTest.php index e7d3d70b..70108eb6 100644 --- a/tests/Constraints/SelfDefinedSchemaTest.php +++ b/tests/Constraints/SelfDefinedSchemaTest.php @@ -69,8 +69,13 @@ public function getValidTests() public function testInvalidArgumentException() { + $value = json_decode('{}'); + $schema = json_decode(''); + $v = new Validator(); + $this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException'); - $v->check(json_decode('{}'), json_decode('')); + + $v->validate($value, $schema); } } diff --git a/tests/Uri/UriRetrieverTest.php b/tests/Uri/UriRetrieverTest.php index c27e49c3..08e338ab 100644 --- a/tests/Uri/UriRetrieverTest.php +++ b/tests/Uri/UriRetrieverTest.php @@ -55,7 +55,7 @@ public function testChildExtendsParentValidTest($childSchema, $parentSchema) $decodedJson = json_decode($json); $decodedJsonSchema = json_decode($childSchema); - $this->validator->check($decodedJson, $decodedJsonSchema); + $this->validator->validate($decodedJson, $decodedJsonSchema); $this->assertTrue($this->validator->isValid()); } @@ -70,7 +70,7 @@ public function testChildExtendsParentInvalidChildTest($childSchema, $parentSche $decodedJson = json_decode($json); $decodedJsonSchema = json_decode($childSchema); - $this->validator->check($decodedJson, $decodedJsonSchema); + $this->validator->validate($decodedJson, $decodedJsonSchema); $this->assertFalse($this->validator->isValid()); } @@ -85,7 +85,7 @@ public function testChildExtendsParentInvalidParentTest($childSchema, $parentSch $decodedJson = json_decode($json); $decodedJsonSchema = json_decode($childSchema); - $this->validator->check($decodedJson, $decodedJsonSchema); + $this->validator->validate($decodedJson, $decodedJsonSchema); $this->assertFalse($this->validator->isValid()); } @@ -101,7 +101,7 @@ public function testResolveRelativeUri($childSchema, $parentSchema) $decodedJson = json_decode($json); $decodedJsonSchema = json_decode($childSchema); - $this->validator->check($decodedJson, $decodedJsonSchema); + $this->validator->validate($decodedJson, $decodedJsonSchema); $this->assertTrue($this->validator->isValid()); } diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index c34954e8..54347911 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -36,7 +36,7 @@ public function testBadAssocSchemaInput() $validator->validate($data, $schema); } - public function testCheck() + public function testDeprecatedCheckDelegatesToValidate() { $schema = json_decode('{"type":"string"}'); $data = json_decode('42'); @@ -47,7 +47,7 @@ public function testCheck() $this->assertFalse($validator->isValid(), 'Validation succeeded, but should have failed.'); } - public function testCoerce() + public function testDeprecatedCoerceDelegatesToValidate() { $schema = json_decode('{"type":"integer"}'); $data = json_decode('"42"');