barkermn01 / unittest-josn-schema
Allows Unit testing of JSON-Schema's against a supplied JSON-Schema schema or an in-schema defined schema
1.1.0
2018-04-21 21:28 UTC
Requires
- php: ^7.2
- justinrainbow/json-schema: ^5.2.7
- phpunit/phpunit: ^7.1
- seld/jsonlint: ^1.7.1
This package is not auto-updated.
Last update: 2025-03-30 07:56:42 UTC
README
A simple and easy to use class to aid in the validation and testing of a JSON-schema.
How to Install
composer require "barkermn01/unittest-josn-schema"
How to use
Sample draft-7 schema for validation
{
"$schema":"http://json-schema.org/draft-07/schema",
"properties":{
"test":{
"type":"string"
}
}
}
Package is released in the namespace UnitTestJSONSchema;
Supply a schema in test cases manually.
$SchemaName = "test.schema.json"; $schemaToTest = file_get_contents(__DIR__ . "/test.schema.json"); $tester = new SchemaTester; $tester->DefineSchema("http://json-schema.org/draft-07/schema"); $tester->TestSchema($schemaToTest); $this->assertFalse($tester->hasErrors(), "Schema '{$SchemaName}' failed vailidation: '".$tester->getErrors());
Allow a schema to define it's own schema to be validated against
$SchemaName = "test.schema.json"; $schemaToTest = file_get_contents(__DIR__ . "/test.schema.json"); $tester = new SchemaTester; $tester->TestSchema($schemaToTest); $this->assertFalse($tester->hasErrors(), "Schema '{$SchemaName}' failed vailidation: '".$tester->getErrors());
License
Licensed under the Appache-2 license.