Skip to content

Commit c35b014

Browse files
committed
bugfix. #10
1 parent 30cceb4 commit c35b014

File tree

3 files changed

+24
-33
lines changed

3 files changed

+24
-33
lines changed

phpunit.xml.dist

+11-19
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="Application Test Suite">
13-
<directory>./tests/</directory>
14-
</testsuite>
15-
</testsuites>
16-
<filter>
17-
<whitelist>
18-
<directory suffix=".php">src/</directory>
19-
</whitelist>
20-
</filter>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
</coverage>
8+
<testsuites>
9+
<testsuite name="Application Test Suite">
10+
<directory>./tests/</directory>
11+
</testsuite>
12+
</testsuites>
2113
</phpunit>

src/CacheTokenRepository.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public function __construct(string $cacheKeyPrefix = null, int $expiresInSeconds
5353
*
5454
* @return \Laravel\Passport\Token
5555
*/
56-
public function find($id)
56+
public function find($id): Token
5757
{
58-
return $this->store()->remember(
58+
return $this->cacheStore()->remember(
5959
$this->itemKey($id),
6060
\now()->addSeconds($this->expiresInSeconds),
6161
function () use ($id) {
@@ -72,9 +72,9 @@ function () use ($id) {
7272
*
7373
* @return \Laravel\Passport\Token|null
7474
*/
75-
public function findForUser($id, $userId)
75+
public function findForUser($id, $userId): ?Token
7676
{
77-
return $this->store()->remember(
77+
return $this->cacheStore()->remember(
7878
$this->itemKey($id),
7979
\now()->addSeconds($this->expiresInSeconds),
8080
function () use ($id, $userId) {
@@ -92,7 +92,7 @@ function () use ($id, $userId) {
9292
*/
9393
public function forUser($userId): Collection
9494
{
95-
return $this->store()->remember(
95+
return $this->cacheStore()->remember(
9696
$this->itemKey($userId),
9797
\now()->addSeconds($this->expiresInSeconds),
9898
function () use ($userId) {
@@ -109,9 +109,9 @@ function () use ($userId) {
109109
*
110110
* @return \Laravel\Passport\Token|null
111111
*/
112-
public function getValidToken($user, $client)
112+
public function getValidToken($user, $client): ?Token
113113
{
114-
return $this->store()->remember(
114+
return $this->cacheStore()->remember(
115115
$this->itemKey($user->getKey()),
116116
\now()->addSeconds($this->expiresInSeconds),
117117
function () use ($client, $user) {
@@ -124,22 +124,22 @@ function () use ($client, $user) {
124124
);
125125
}
126126

127-
public function itemKey(string $key)
127+
public function itemKey(string $key): string
128128
{
129129
return $this->cacheKeyPrefix . $key;
130130
}
131131

132-
public function store(): Repository
132+
public function cacheStore(): Repository
133133
{
134134
$store = Cache::store($this->cacheStore);
135135

136-
return $store instanceof TaggableStore ? $store->tags($this->cacheTags) : $store;
136+
return $store->getStore() instanceof TaggableStore ? $store->tags($this->cacheTags) : $store;
137137
}
138138

139139
public function revokeAccessToken($id)
140140
{
141141
parent::revokeAccessToken($id);
142142

143-
$this->store()->forget($this->itemKey($id));
143+
$this->cacheStore()->forget($this->itemKey($id));
144144
}
145145
}

tests/FeatureTest.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Illuminate\Contracts\Hashing\Hasher;
77
use Illuminate\Contracts\Routing\Registrar;
88
use Illuminate\Support\Facades\Auth;
9-
use Illuminate\Support\Facades\Cache;
109
use Illuminate\Support\Str;
1110
use Laravel\Passport\Client;
1211
use Laravel\Passport\ClientRepository;
@@ -100,13 +99,13 @@ public function test_it_can_cache_token()
10099

101100
// revoke token
102101
$token = $tokenRepository->findValidToken($user, $client);
103-
$this->assertTrue(Cache::has(app(TokenRepository::class)->itemKey($token->id)));
102+
$this->assertTrue($tokenRepository->cacheStore()->has(app(TokenRepository::class)->itemKey($token->id)));
104103

105104
$tokenRepository->revokeAccessToken($token->id);
106105
$token->refresh();
107106
$this->assertTrue($token->revoked);
108107

109-
$this->assertFalse(Cache::has($tokenRepository->itemKey($token->id)));
108+
$this->assertFalse($tokenRepository->cacheStore()->has($tokenRepository->itemKey($token->id)));
110109

111110
// logout
112111
RequestGuard::macro('logout', function () {

0 commit comments

Comments
 (0)