PHP code example of gammabeam82 / schema-checker

1. Go to this page and download the library: Download gammabeam82/schema-checker library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gammabeam82 / schema-checker example snippets


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()
        );
    }
}