Skip to content

Commit 7d7f43a

Browse files
authored
Merge pull request #476 from localheinz/fix/deprecate
Fix: Mark check() and coerce() as deprecated
2 parents 92ddcea + 284f3e5 commit 7d7f43a

File tree

8 files changed

+22
-13
lines changed

8 files changed

+22
-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
@@ -72,6 +72,8 @@ public function validate(&$value, $schema = null, $checkMode = null)
7272

7373
/**
7474
* Alias to validate(), to maintain backwards-compatibility with the previous API
75+
*
76+
* @deprecated
7577
*/
7678
public function check($value, $schema)
7779
{
@@ -80,6 +82,8 @@ public function check($value, $schema)
8082

8183
/**
8284
* Alias to validate(), to maintain backwards-compatibility with the previous API
85+
*
86+
* @deprecated
8387
*/
8488
public function coerce(&$value, $schema)
8589
{

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,13 @@ public function getValidTests()
6969

7070
public function testInvalidArgumentException()
7171
{
72+
$value = json_decode('{}');
73+
$schema = json_decode('');
74+
7275
$v = new Validator();
76+
7377
$this->setExpectedException('\JsonSchema\Exception\InvalidArgumentException');
74-
$v->check(json_decode('{}'), json_decode(''));
78+
79+
$v->validate($value, $schema);
7580
}
7681
}

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
@@ -35,7 +35,7 @@ public function testBadAssocSchemaInput()
3535
$validator->validate($data, $schema);
3636
}
3737

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

49-
public function testCoerce()
49+
public function testDeprecatedCoerceDelegatesToValidate()
5050
{
5151
$schema = json_decode('{"type":"integer"}');
5252
$data = json_decode('"42"');

0 commit comments

Comments
 (0)