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

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.