Example #1
0
    public function test_should_throw_exception_for_incorrect_json()
    {
        $this->given($schema = $this->newTestedInstance('{}'), $json = new \Sanpi\Behatch\Json\Json('{}'), $validator = new \mock\JsonSchema\Validator(), $validator->getMockController()->check = false, $validator->getMockController()->getErrors = [['property' => 'foo', 'message' => 'invalid'], ['property' => 'bar', 'message' => 'not found']])->exception(function () use($schema, $json, $validator) {
            $schema->validate($json, $validator);
        })->hasMessage(<<<ERROR
JSON does not validate. Violations:
  - [foo] invalid
  - [bar] not found

ERROR
);
    }
    public function test_should_throw_exception_for_incorrect_json()
    {
        $this->given($sut = new SUT('schema.json'), $json = new \Rezzza\RestApiBehatExtension\Json\Json('{}'), $validator = new \mock\JsonSchema\Validator(), $validator->getMockController()->check = false, $validator->getMockController()->getErrors = [['property' => 'foo', 'message' => 'invalid'], ['property' => 'bar', 'message' => 'not found']], $this->mockGenerator->orphanize('__construct'), $refResolver = new \mock\JsonSchema\RefResolver(), $refResolver->getMockController()->resolve = 'mySchema')->exception(function () use($sut, $json, $validator, $refResolver) {
            $sut->validate($json, $validator, $refResolver);
        })->hasMessage(<<<ERROR
JSON does not validate. Violations:
  - [foo] invalid
  - [bar] not found

ERROR
);
    }
    public function test_should_throw_exception_for_incorrect_json()
    {
        $this->given($sut = new SUT('{}'), $json = new \Rezzza\RestApiBehatExtension\Json\Json('{}'), $validator = new \mock\JsonSchema\Validator(), $validator->getMockController()->check = false, $validator->getMockController()->getErrors = array(array('property' => 'foo', 'message' => 'invalid'), array('property' => 'bar', 'message' => 'not found')))->exception(function () use($sut, $json, $validator) {
            $sut->validate($json, $validator);
        })->hasMessage(<<<ERROR
JSON does not validate. Violations:
  - [foo] invalid
  - [bar] not found

ERROR
);
    }