PHP code example of sixlive / json-schema-assertions

1. Go to this page and download the library: Download sixlive/json-schema-assertions 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/ */

    

sixlive / json-schema-assertions example snippets


use sixlive\JsonSchemaAssertions\Concerns\AssertJsonSchema;

class ExampleTest extends TestCase
{
    use AssertsJsonSchema;

    public function setUp()
    {
        parent::setUp();

        $this->setJsonSchemaBasePath(__DIR__.'/../Schemas');
    }

    /** @test */
    function it_has_a_valid_response()
    {
        $this->schemaAssertion
            ->schema('foo')
            ->assert('{"foo": "bar"}');
    }
}

/** @test */
public function it_has_a_valid_response()
{
    $schema = [
        'type' => 'object',
        'properties' => [
           'foo' => [
                'type' => 'string',
           ],
         ],
         'assert('{"foo": "bar"}');

    // Schema from a file
    (new SchemaAssertion)->schema(__DIR__.'/../schemas/foo.json'))
        ->assert('{"foo": "bar"}');

    // Remote schema
    (new SchemaAssertion)->schema('https://docs.foo.io/schemas/foo.json')
        ->assert('{"foo": "bar"}')

    // Schema from a path
    (new SchemaAssertion(__DIR__.'/../schemas/'))
        ->schema('foo')
        ->assert('{"foo": "bar"}');
}