Inspired by apidoc-plugin-swagger https://github.com/sadeghmohebbi/apidoc-plugin-swagger. Thank you for showing me that we can also build own plugin for apidoc :)
Hopefully this plugin will helps developer to do API testing by referring to the apidoc schema.
- This plugin only support JSON request and response.
- This plugin skipped any authorization token such as bearer etc.
- Please ensure your API can take parameter "skipToken":true if you want to disable API authorization token.
npm i haizadvnet/apidoc-plugin-codeception -g
ApiDocCest.php
will be generated once you generate your apidoc.
-
Add
"codeception_path":[TEST API PATH]
inside your APIdoc config file to inform plugin where to generate your codeception api testing script. Example"codeception_path":tests/api
-
Add
"check_status_200":true
inside your APIdoc config file if you want to check all API response status code is 200. -
Add
"cest_file_name":"[FILE NAME].php"
inside your APIdoc config file to rename your cest file name. Default file name isApiDocCest.php
. -
Add
"see_response_contains":"[FIND THIS STRING]"
inside your APIdoc config file to enable Codeception's seeResponseContains method. Leave the value as"see_response_contains":""
if to disable the method.
Refer https://github.com/haizadvnet/apidoc-plugin-codeception/blob/master/config.json
apidoc -i . -o doc/ -c doc/config.json
<?php
class ApiDocCest
{
public function getUser(\ApiTester $I)
{
$I->haveHttpHeader('accept', 'application/json');
$I->haveHttpHeader('content-type', 'application/json');
$I->sendPost('/user.php', ['Id' => '1','skipToken'=>true]);
$I->seeResponseIsJson();
}
}
?>
Todo list:
- Pass parameter from apidoc into codeception api testing script
- Add support for Codeception's seeResponseContains method
- Add support for Codeception's seeResponseContainsJson method