Skip to content

Commit 3b34779

Browse files
committed
Fix: Mark check() and coerce() as deprecated
1 parent dfdcb5b commit 3b34779

File tree

8 files changed

+17
-13
lines changed

8 files changed

+17
-13
lines changed

bin/validate-json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ if (isset($arOptions['--dump-schema'])) {
217217

218218
try {
219219
$validator = new JsonSchema\Validator();
220-
$validator->check($data, $schema);
220+
$validator->validate($data, $schema);
221221

222222
if ($validator->isValid()) {
223223
if(isset($arOptions['--verbose'])) {

demo/demo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
// Validate
88
$validator = new JsonSchema\Validator();
9-
$validator->check($data, (object) array('$ref' => 'file://' . realpath('schema.json')));
9+
$validator->validate($data, (object) array('$ref' => 'file://' . realpath('schema.json')));
1010

1111
if ($validator->isValid()) {
1212
echo "The supplied JSON validates against the schema.\n";

src/JsonSchema/Validator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public function validate(&$value, $schema = null, $checkMode = null)
7474

7575
/**
7676
* Alias to validate(), to maintain backwards-compatibility with the previous API
77+
*
78+
* @deprecated
7779
*/
7880
public function check($value, $schema)
7981
{
@@ -82,6 +84,8 @@ public function check($value, $schema)
8284

8385
/**
8486
* Alias to validate(), to maintain backwards-compatibility with the previous API
87+
*
88+
* @deprecated
8589
*/
8690
public function coerce(&$value, $schema)
8791
{

tests/Constraints/LongArraysTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testLongStringArray()
4141

4242
$validator = new Validator(new Factory($schemaStorage));
4343
$checkValue = json_decode($input);
44-
$validator->check($checkValue, $schema);
44+
$validator->validate($checkValue, $schema);
4545
$this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
4646
}
4747

@@ -69,7 +69,7 @@ public function testLongNumberArray()
6969

7070
$validator = new Validator(new Factory($schemaStorage));
7171
$checkValue = json_decode($input);
72-
$validator->check($checkValue, $schema);
72+
$validator->validate($checkValue, $schema);
7373
$this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
7474
}
7575

@@ -97,7 +97,7 @@ public function testLongIntegerArray()
9797

9898
$validator = new Validator(new Factory($schemaStorage));
9999
$checkValue = json_decode($input);
100-
$validator->check($checkValue, $schema);
100+
$validator->validate($checkValue, $schema);
101101
$this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
102102
}
103103

tests/Constraints/PointerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testVariousPointers()
8383

8484
$validator = new Validator();
8585
$checkValue = json_decode(json_encode($value));
86-
$validator->check($checkValue, json_decode(json_encode($schema)));
86+
$validator->validate($checkValue, json_decode(json_encode($schema)));
8787

8888
$this->assertEquals(
8989
array(

tests/Constraints/SelfDefinedSchemaTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,6 @@ public function testInvalidArgumentException()
7171
{
7272
$v = new Validator();
7373
$this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException');
74-
$v->check(json_decode('{}'), json_decode(''));
74+
$v->validate(json_decode('{}'), json_decode(''));
7575
}
7676
}

tests/Uri/UriRetrieverTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function testChildExtendsParentValidTest($childSchema, $parentSchema)
5555
$decodedJson = json_decode($json);
5656
$decodedJsonSchema = json_decode($childSchema);
5757

58-
$this->validator->check($decodedJson, $decodedJsonSchema);
58+
$this->validator->validate($decodedJson, $decodedJsonSchema);
5959
$this->assertTrue($this->validator->isValid());
6060
}
6161

@@ -70,7 +70,7 @@ public function testChildExtendsParentInvalidChildTest($childSchema, $parentSche
7070
$decodedJson = json_decode($json);
7171
$decodedJsonSchema = json_decode($childSchema);
7272

73-
$this->validator->check($decodedJson, $decodedJsonSchema);
73+
$this->validator->validate($decodedJson, $decodedJsonSchema);
7474
$this->assertFalse($this->validator->isValid());
7575
}
7676

@@ -85,7 +85,7 @@ public function testChildExtendsParentInvalidParentTest($childSchema, $parentSch
8585
$decodedJson = json_decode($json);
8686
$decodedJsonSchema = json_decode($childSchema);
8787

88-
$this->validator->check($decodedJson, $decodedJsonSchema);
88+
$this->validator->validate($decodedJson, $decodedJsonSchema);
8989
$this->assertFalse($this->validator->isValid());
9090
}
9191

@@ -101,7 +101,7 @@ public function testResolveRelativeUri($childSchema, $parentSchema)
101101
$decodedJson = json_decode($json);
102102
$decodedJsonSchema = json_decode($childSchema);
103103

104-
$this->validator->check($decodedJson, $decodedJsonSchema);
104+
$this->validator->validate($decodedJson, $decodedJsonSchema);
105105
$this->assertTrue($this->validator->isValid());
106106
}
107107

tests/ValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testBadAssocSchemaInput()
3636
$validator->validate($data, $schema);
3737
}
3838

39-
public function testCheck()
39+
public function testDeprecatedCheckStillValidates()
4040
{
4141
$schema = json_decode('{"type":"string"}');
4242
$data = json_decode('42');
@@ -47,7 +47,7 @@ public function testCheck()
4747
$this->assertFalse($validator->isValid(), 'Validation succeeded, but should have failed.');
4848
}
4949

50-
public function testCoerce()
50+
public function testDeprecatedCoerceStillValidates()
5151
{
5252
$schema = json_decode('{"type":"integer"}');
5353
$data = json_decode('"42"');

0 commit comments

Comments
 (0)