forked from laravel/passport
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBridgeRefreshTokenRepositoryTest.php
62 lines (48 loc) · 1.68 KB
/
BridgeRefreshTokenRepositoryTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace Laravel\Passport\Tests;
use Laravel\Passport\Bridge\RefreshTokenRepository as BridgeRefreshTokenRepository;
use Laravel\Passport\RefreshTokenRepository;
use Mockery as m;
use PHPUnit\Framework\TestCase;
class BridgeRefreshTokenRepositoryTest extends TestCase
{
protected function tearDown(): void
{
m::close();
}
public function test_it_can_determine_if_a_refresh_token_is_revoked()
{
$refreshToken = new RevokedRefreshToken;
$repository = $this->repository($refreshToken);
$this->assertTrue($repository->isRefreshTokenRevoked('tokenId'));
}
public function test_a_refresh_token_is_also_revoked_if_it_cannot_be_found()
{
$refreshToken = null;
$repository = $this->repository($refreshToken);
$this->assertTrue($repository->isRefreshTokenRevoked('tokenId'));
}
public function test_it_can_determine_if_a_refresh_token_is_not_revoked()
{
$refreshToken = new ActiveRefreshToken;
$repository = $this->repository($refreshToken);
$this->assertFalse($repository->isRefreshTokenRevoked('tokenId'));
}
private function repository($refreshToken): BridgeRefreshTokenRepository
{
$refreshTokenRepository = m::mock(RefreshTokenRepository::class)->makePartial();
$refreshTokenRepository->shouldReceive('find')
->with('tokenId')
->andReturn($refreshToken);
$events = m::mock('Illuminate\Contracts\Events\Dispatcher');
return new BridgeRefreshTokenRepository($refreshTokenRepository, $events);
}
}
class ActiveRefreshToken
{
public $revoked = false;
}
class RevokedRefreshToken
{
public $revoked = true;
}