Skip to content

Instantly share code, notes, and snippets.

@renderorange
Last active October 13, 2015 04:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renderorange/efbc140de1a3ea2cfeaf to your computer and use it in GitHub Desktop.
Save renderorange/efbc140de1a3ea2cfeaf to your computer and use it in GitHub Desktop.
change_this
<?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' => 'ppadmin@example.com', '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