Skip to content

Commit d65c987

Browse files
authored
Expand token authenticator docs (#724)
Add an example for `getToken()` in the test case. Fixes #723
2 parents 445aef3 + 5beaee1 commit d65c987

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

docs/en/testing.rst

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,23 @@ Token based authentication
5151
With token based authentication you need to simulate the
5252
``Authorization`` header. After getting valid token setup the request::
5353

54-
public function testGet()
55-
{
56-
$token = $this->getToken();
57-
$this->configRequest([
58-
'headers' => ['Authorization' => 'Bearer ' . $token]
59-
]);
60-
$this->get('/api/bookmarks');
61-
$this->assertResponseOk();
62-
}
54+
protected function getToken(): string
55+
{
56+
// Get a token for a known user
57+
$user = $this->fetchTable('Users')->get(1, contain: ['ApiTokens']);
58+
59+
return $user->api_tokens[0]->token;
60+
}
61+
62+
public function testGet()
63+
{
64+
$token = $this->getToken();
65+
$this->configRequest([
66+
'headers' => ['Authorization' => 'Bearer ' . $token]
67+
]);
68+
$this->get('/api/bookmarks');
69+
$this->assertResponseOk();
70+
}
6371

6472

6573
Basic/Digest based authentication

0 commit comments

Comments
 (0)