PHP code example of jtmcc / lara-schema-validation

1. Go to this page and download the library: Download jtmcc/lara-schema-validation 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/ */

    

jtmcc / lara-schema-validation example snippets


use JTMcC\LaraSchemaValidation\SchemaValidator;

public function testIndexValidation()
{
    // Act
    $response = $this->getJson(route('api.posts.index'));

    // Assert
    SchemaValidator::validateResponseCollection($response, 'post.json');
}

public function testShowValidation()
{
    // Act
    $response = $this->getJson(route('api.posts.show', 1));

    // Assert
    SchemaValidator::validateResponse($response, 'post.json');
}

test('it validates schema', function () {
    $response = $this->getJson(route('api.posts.show', 1));

    expect($response)->toMatchSchema('post.json');
});

test('it validates schema collection', function () {
    $response = $this->getJson(route('api.posts.index'));

    expect($response)->toMatchSchemaCollection('post.json');
});