Skip to content

Fix: Mark check() and coerce() as deprecated #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/validate-json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ if (isset($arOptions['--dump-schema'])) {

try {
$validator = new JsonSchema\Validator();
$validator->check($data, $schema);
$validator->validate($data, $schema);
Copy link
Contributor Author

@localheinz localheinz Dec 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to use Validator::validate() here.


if ($validator->isValid()) {
if(isset($arOptions['--verbose'])) {
Expand Down
2 changes: 1 addition & 1 deletion demo/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably makes sense to use Validator::validate() here, too.


if ($validator->isValid()) {
echo "The supplied JSON validates against the schema.\n";
Expand Down
4 changes: 4 additions & 0 deletions src/JsonSchema/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Constraints/LongArraysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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));
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Constraints/PointerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion tests/Constraints/SelfDefinedSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions tests/Uri/UriRetrieverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand All @@ -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());
}

Expand All @@ -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());
}

Expand All @@ -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());
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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"');
Expand Down