Skip to content

AsJson Step Decorator

Choose a tag to compare

@DavertMik DavertMik released this 17 Nov 12:52
· 46 commits to master since this release

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\AsJson

or if you use API template:

suites:
    api:
        actor: ApiTester
        step_decorators:
            - \Codeception\Step\AsJson

Rebuild actions:

./vendor/bin/codecept build

And you get new actions:

  • sendPostAsJson
  • sendGetAsJson

... 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'])