Skip to content

Instantly share code, notes, and snippets.

@fityanos
Last active May 8, 2019 06:13
Show Gist options
  • Save fityanos/f31df4ed15443e20db1c59acf9b9e77c to your computer and use it in GitHub Desktop.
Save fityanos/f31df4ed15443e20db1c59acf9b9e77c to your computer and use it in GitHub Desktop.
exampleClass
<?php
use \Codeception\Util\HttpCode as responseValidate;
/**
* Class classNameCest
*
* @group apiLevelOne
* @group apiLevelTwo
*
*/
class classNameCest
{
/**
* @param ApiGuy $I
* @throws Exception
*/
protected function GenerateToken(ApiGuy $I)
{
$I->haveHttpHeader('Accept', 'application/json');
$I->haveHttpHeader('Content-Type', 'application/json');
$I->sendPOST('/user/auth/token', [
'username' => '$userName',
'password' => '$password'
]);
/** Assertions for status code && JSON body */
$I->seeResponseCodeIs(responseValidate::OK); // 200
$I->seeResponseIsJson();
$I->seeResponseContains('access_token');
/**fetch token in $token*/
$token = $I->grabDataFromResponseByJsonPath('$.access_token');
$this->token = $token;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment