AsJson Step Decorator
Step descorator AsJson was introduced to simplify sending and parsing JSON requests and responses.
Add it to suite configuration:
actor: ApiTester
step_decorators:
- \Codeception\Step\AsJsonor if you use API template:
suites:
api:
actor: ApiTester
step_decorators:
- \Codeception\Step\AsJsonRebuild actions:
./vendor/bin/codecept build
And you get new actions:
sendPostAsJsonsendGetAsJson
... basically all send* methods will receive AsJson pair which sends request in JSON and returns parsed response:
<?php
$user = $I->sendPostAsJson('user', ['id' => 1]);
codecept_debug($user['id'])
$I->assertEquals(1, $user['id'])