alexpts/codeception-json-schema

This package is abandoned and no longer maintained. No replacement package was suggested.

Simple validate response by json schema

1.0.1 2020-03-24 11:17 UTC

This package is auto-updated.

Last update: 2023-05-24 18:22:05 UTC


README

SensioLabsInsight

Build Status Code Coverage Code Climate Scrutinizer Code Quality

Simple validator json schema + module for codeception.

Example (without codeception):

use \PTS\JsonSchema;

$validator = new JsonSchema;
$schemasDir = dirname(__DIR__). '/schemas/';
$validator->loadAllSchemas($schemasDir);
$responseBody = \json_encode(['id' => 1, 'name' => 'Alex']);

$errorsMessage = $validator->validateJsonSchema($responseBody, 'v1/users/user-model.json');
if (null !== $errorsMessage) {
    throw \Exception($errorsMessage);
}

Example (codeception module):

class RegionsCest
{
    public function _before(FunctionalTester $I)
    {
        $I->haveHttpHeader('Authorization', 'Bearer xxx');
    }

    public function getRegionsList(FunctionalTester $I)
    {
        $I->sendGET('/v1/regions/');
        $I->seeResponseCodeIs(200);
        $I->validateJsonSchema($I->grabResponse(), '/v1/regions/get.json');
    }
}