Skip to content

Commit

Permalink
Merge pull request #476 from localheinz/fix/deprecate
Browse files Browse the repository at this point in the history
Fix: Mark check() and coerce() as deprecated
  • Loading branch information
bighappyface authored Dec 31, 2017
2 parents 92ddcea + 284f3e5 commit 7d7f43a
Show file tree
Hide file tree
Showing 8 changed files with 22 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 @@ -72,6 +72,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 @@ -80,6 +82,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));
}
}
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 @@ -35,7 +35,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 @@ -46,7 +46,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

0 comments on commit 7d7f43a

Please sign in to comment.