alexpts / codeception-json-schema
此包已 废弃 并不再维护。未建议替代包。
通过 JSON schema 简单验证响应
1.0.1
2020-03-24 11:17 UTC
Requires
- php: ^7.1
- justinrainbow/json-schema: ^5.2
Requires (Dev)
- codeception/codeception: ^2.3.5
- phpunit/phpunit: ^6.2.0
This package is auto-updated.
Last update: 2023-05-24 18:22:05 UTC
README
简单的 JSON schema 验证器 + Codeception 模块。
示例(不带 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); }
示例(codeception 模块)
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'); } }