Last active
October 13, 2015 04:44
-
-
Save renderorange/efbc140de1a3ea2cfeaf to your computer and use it in GitHub Desktop.
change_this
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 Auth extends TestCase | |
{ | |
private $auth_token; | |
// verify API response if invalid credentials | |
function test_invalid_credentials() | |
{ | |
$this->post('/authenticate', ['email' => 'false', 'password' => 'false']) | |
->seeJson([ | |
'error' => 'invalid_credentials', | |
]); | |
} | |
// verify API response if valid credentials | |
function test_valid_credentials() | |
{ | |
$token_obj = json_decode($this->call('POST', '/authenticate', ['email' => '[email protected]', 'password' => 'secret'])->getContent()); | |
$this->auth_token = $token_obj->{'token'}; <----- | |
$this->see('token'); | |
} | |
// verify API response if no token provided | |
function test_no_token() | |
{ | |
$this->get('/user/1') | |
->seeJson([ | |
'error' => 'token_not_provided', | |
]); | |
} | |
// verify API response if invalid token provided | |
function test_invalid_token() | |
{ | |
$this->post('/user/1', ['Authorization' => 'Bearer false']) | |
->seeJson([ | |
'error' => 'token_not_provided', | |
]); | |
} | |
// verify API response if valid token provided | |
function test_valid_token() | |
{ | |
var_dump($this->auth_token); <----- NULL | |
$this->post('/user/1', ['Authorization' => "Bearer $this->auth_token"]) | |
->seeJson([ | |
'id' => '1', | |
]); | |
//$response = $this->call('POST', '/user/1', ['Authorization' => "Bearer $this->auth_token"]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment