gammabeam82 / schema-checker
Simple schema validation library with no external dependencies.
1.0.0
2018-12-27 10:05 UTC
Requires
- php: >=7.1
- ext-json: *
- ext-mbstring: *
Requires (Dev)
This package is auto-updated.
Last update: 2025-04-28 05:09:11 UTC
README
Description
This library provides an easy way to validate api responses.
Installation
composer require --dev gammabeam82/schema-checker
Usage
use Gammabeam82\SchemaChecker\SchemaChecker; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; class CategoryControllerTest extends WebTestCase { /** * @var Client */ protected static $client; /** * @var SchemaChecker */ protected static $schemaChecker; /** * @inheritdoc */ public function setUpBeforeClass() { static::$client = static::createClient(); static::$schemaChecker = new SchemaChecker(); } public function testListAction(): void { static::$client->request('GET', '/api/v1/categories/'); $response = static::$client->getResponse(); $this->assertEquals(Response::HTTP_OK, $response->getStatusCode()); $this->assertTrue( static::$schemaChecker->assertDataMatchesSchema($response->getContent(), [ 'id' => 'integer', 'name' => 'string', 'image' => 'string|nullable', 'is_active' => 'boolean', 'products' => [ 'nullable' => true, 'id' => 'integer', 'name' => 'string', 'description' => 'string', 'images' => [ 'nullable' => true, 'id' => 'integer', 'filename' => 'string' ] ] ]), static::$schemaChecker->getViolations() ); } }