Last active
November 27, 2019 04:12
-
-
Save remoharsono/ba75c90da0f2d04eb624578e2769419e to your computer and use it in GitHub Desktop.
Reusing token in Codeception
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Helper; | |
class Api extends \Codeception\Module | |
{ | |
public $credentials = array( | |
'username' => 'remo', | |
'password' => '12345678' | |
); | |
private $jwt; | |
public function getToken() { | |
return $this->jwt; | |
} | |
public function _before(\Codeception\TestInterface $test) { | |
$I = $this->getModule('REST'); | |
$I->haveHttpHeader('Content-Type', 'application/json'); | |
$I->sendPOST("/auth/login", $this->arrCredentials); | |
$I->seeResponseCodeIs(200); | |
$I->seeResponseIsJson(); | |
$response = $I->grabResponse(); | |
$json = json_decode((string)$jesponse); | |
if ($json->result == 'OK') { | |
$this->jwt = $json->jwt; | |
} else { | |
// .... | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class ApiCest | |
{ | |
private $token; | |
function createMeetingTest(ApiTester $I) { | |
$data = array( | |
"meeting_title" => "Meeting title", | |
"meeting_date" => "2019-11-21 10:00:00" | |
); | |
$this->token = $I->getToken(); | |
$I->wantToTest('Create a meeting'); | |
$I->amBearerAuthenticated($this->token); | |
$I->sendPOST('/meetings', $data); | |
$I->seeResponseCodeIs(200); | |
$I->seeResponseIsJson(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"result": "OK", | |
"jwt": "blablablabla", | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment