forked from jsonrainbow/json-schema
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow the schema to be an associative array
Implements jsonrainbow#388.
- Loading branch information
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace JsonSchema\Tests; | ||
|
||
use JsonSchema\Constraints\Constraint; | ||
use JsonSchema\Validator; | ||
|
||
class ValidatorTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testValidateWithAssocSchema() | ||
{ | ||
$schema = json_decode('{"type":"string"}', true); | ||
$data = json_decode('42', true); | ||
|
||
$validator = new Validator(); | ||
$validator->validate($data, $schema, Constraint::CHECK_MODE_NORMAL); | ||
|
||
$this->assertFalse($validator->isValid(), 'Validation succeeded, but should have failed.'); | ||
} | ||
|
||
public function testCheck() | ||
{ | ||
$schema = json_decode('{"type":"string"}'); | ||
$data = json_decode('42'); | ||
|
||
$validator = new Validator(); | ||
$validator->check($data, $schema, Constraint::CHECK_MODE_NORMAL); | ||
|
||
$this->assertFalse($validator->isValid(), 'Validation succeeded, but should have failed.'); | ||
} | ||
|
||
public function testCoerce() | ||
{ | ||
$schema = json_decode('{"type":"integer"}'); | ||
$data = json_decode('"42"'); | ||
|
||
$validator = new Validator(); | ||
$validator->coerce($data, $schema); | ||
|
||
$this->assertTrue($validator->isValid(), 'Validation failed, but should have succeeded.'); | ||
} | ||
} |