BaseTestCase.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace JsonSchema\Tests;
  3. use JsonSchema\Validator;
  4. abstract class BaseTestCase extends \PHPUnit_Framework_TestCase
  5. {
  6. /**
  7. * @dataProvider getInvalidTests
  8. */
  9. public function testInvalidCases($input, $schema, $checkMode = Validator::CHECK_MODE_NORMAL, $errors = array())
  10. {
  11. $validator = new Validator($checkMode);
  12. $validator->check(json_decode($input), json_decode($schema));
  13. if (array() !== $errors) {
  14. $this->assertEquals($errors, $validator->getErrors(), print_r($validator->getErrors(),true));
  15. }
  16. $this->assertFalse($validator->isValid(), print_r($validator->getErrors(), true));
  17. }
  18. /**
  19. * @dataProvider getValidTests
  20. */
  21. public function testValidCases($input, $schema, $checkMode = Validator::CHECK_MODE_NORMAL)
  22. {
  23. $validator = new Validator($checkMode);
  24. $validator->check(json_decode($input), json_decode($schema));
  25. $this->assertTrue($validator->isValid(), print_r($validator->getErrors(), true));
  26. }
  27. abstract public function getValidTests();
  28. abstract public function getInvalidTests();
  29. }