for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace sixlive\Laravel\JsonSchemaAssertions;
use Swaggest\JsonSchema\Schema;
use Swaggest\JsonSchema\InvalidValue;
use PHPUnit\Framework\Assert as PHPUnit;
use sixlive\Laravel\JsonSchemaAssertions\Support\Str;
class SchemaAssertion
{
protected $schema;
/**
* @param array|string $schema
* @return void
@return
Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.
Please refer to the PHP core documentation on constructors.
*/
public function __construct($schema)
if (is_array($schema)) {
$schema = json_encode($schema);
}
if (is_string($schema) && Str::isJson($schema)) {
$schema = json_decode($schema);
$this->schema = Schema::import($schema);
* Assert JSON against the loaded schema
*
* @param string $data
public function assert(string $data)
try {
$this->schema->in(json_decode($data));
} catch (InvalidValue $e) {
PHPUnit::fail($e->getMessage());
PHPUnit::assertTrue(true);
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.