2017 © Pedro PelĂĄez
 

library codeception-json-schema

Json schema module for validate response by json schema for codeception test framework

image

digitaladapt/codeception-json-schema

Json schema module for validate response by json schema for codeception test framework

  • Friday, August 11, 2017
  • by digitaladapt
  • Repository
  • 1 Watchers
  • 3 Stars
  • 1,392 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 6 Versions
  • 87 % Grown

The README.md

codeception-json-schema

Codeception Module to validate json on a schema., (*1)

Installation

composer require digitaladapt/codeception-json-schema

Usage

<?php
class MessageApiCest
{
    public function aTest(ApiTester $I)
    {
        /* call api */
        $I->wantTo('Ensure API Returns Json which matches schema file.');
        $I->sendGET('/path/to/api');

        /* check if api matches schema */
        $I->seeResponseIsValidOnSchemaFile('/path/to/schema.json');
    }

    public function bTest(ApiTester $I)
    {
        /* call api */
        $I->wantTo('Ensure API Returns Json which matches schema file.');
        $I->sendGET('/path/to/api');

        /* alternative syntax, check if api matches schema */
        $I->canSeeResponseIsValidOnSchemaFile('/path/to/schema.json');
    }

    public function cTest(ApiTester $I)
    {
        /* call api */
        $I->wantTo('Ensure API Returns Json which matches inline schema.');
        $I->sendGET('/path/to/api');

        /* if you don't have a separate schema file, that is alright, you can use inline schema */
        /* this schema expects the api to return something like {"message": "SOME_STRING"} */
        /* schema as php objects */
        $schema = (object)[
            'type' => 'object',
            'properties' => (object)[
                'message' => (object)[
                    'type' => 'string',
                ],
            ],
            'required' => ['message'],
        ];

        $I->seeResponseIsValidOnSchema($schema);
    }

    public function dTest(ApiTester $I)
    {
        /* call api */
        $I->wantTo('Ensure API Returns Json which matches inline schema.');
        $I->sendGET('/path/to/api');

        /* if you don't have a separate schema file, that is alright, you can use inline schema */
        /* this schema expects the api to return something like {"message": "SOME_STRING"} */
        /* json string, must be decoded before checking if response is valid */
        $jsonSchema = '{"type":"object","properties":{"message":{"type":"string"}},"required":["message"]}';

        /* alternative syntax, notice we decoded the json string */
        $I->canSeeResponseIsValidOnSchema(json_decode($jsonSchema));
    }
}

Also See

Codeception has a built-in syntax for simple json matches, however it is not compatible with json schema, which is why this was created., (*2)

<?php
class MessageApiCest
{
    public function eTest(ApiTester $I)
    {
        /* call api */
        $I->wantTo('Ensure API Returns Json which matches type.');
        $I->sendGET('/path/to/api');

        /* this type expects the api to return something like {"message": "SOME_STRING"} */
        $I->seeResponseMatchesJsonType([
            'message' => 'string',
        ]);
    }
}

Contributing

If you notice anything wrong or have any suggestions on how to make this better, please open an issue., (*3)

The Versions

11/08 2017

dev-master

9999999-dev https://github.com/digitaladapt/codeception-json-schema

Json schema module for validate response by json schema for codeception test framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cnam
by Andrew Stowell
by Daniel François

schema json functional testing

11/08 2017

v0.1.2

0.1.2.0 https://github.com/digitaladapt/codeception-json-schema

Json schema module for validate response by json schema for codeception test framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cnam
by Andrew Stowell
by Daniel François

schema json functional testing

11/08 2017

v0.1.1

0.1.1.0 https://github.com/digitaladapt/codeception-json-schema

Json schema module for validate response by json schema for codeception test framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cnam
by Andrew Stowell

schema json functional testing

11/08 2017

v0.1.0

0.1.0.0

Json schema module for validate response by json schema for codeception test framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cnam
by Andrew Stowell

10/08 2017

v0.0.2

0.0.2.0

Json schema module for validate response by json schema for codeception test framework

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar cnam

18/04 2015

0.0.1

0.0.1.0

Json schema module for validate response by json schema for codeception test framework

  Sources   Download

MIT

The Requires

 

by Avatar cnam