/** * @Given /^I have a valid authentication token$/ */ public function iHaveAValidAuthenticationToken() { $my_api = new test_API("test.api.com"); try { $obj = $my_api->getToken(self::GRANT_TYPE, self::USERNAME, self::PASSWORD, self::CLIENT_ID, self::CLIENT_SECRET); if ($obj["http_code"] == 200) { self::$the_auth_token = $obj["access_token"]; //print_r($obj); echo "\n Access token = " . self::$the_auth_token . "\n"; } else { //this means the http response code is either 400 or 401 print_r($obj); throw new Exception("Expecting HTTP response to be 200 but received " . $obj["http_code"]); } } catch (Exception $e) { // Process the error throw new Exception($e->getMessage()); } }