Skip to content

Commit

Permalink
Fix: Mark check() and coerce() as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
localheinz committed Dec 30, 2017
1 parent dfdcb5b commit 3b34779
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
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);

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')));

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
2 changes: 1 addition & 1 deletion tests/Constraints/SelfDefinedSchemaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,6 @@ public function testInvalidArgumentException()
{
$v = new Validator();
$this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException');
$v->check(json_decode('{}'), json_decode(''));
$v->validate(json_decode('{}'), json_decode(''));
}
}
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 testDeprecatedCheckStillValidates()
{
$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 testDeprecatedCoerceStillValidates()
{
$schema = json_decode('{"type":"integer"}');
$data = json_decode('"42"');
Expand Down

0 comments on commit 3b34779

Please sign in to comment.