-
Notifications
You must be signed in to change notification settings - Fork 536
/
FluentRefreshTokenTest.php
66 lines (50 loc) · 2.31 KB
/
FluentRefreshTokenTest.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
63
64
65
66
<?php
use LucaDegasperi\OAuth2Server\Storage\FluentRefreshToken;
use Mockery as m;
class FluentRefreshTokenTest extends DBTestCase
{
public function getRefreshTokenRepository()
{
$server = m::mock('League\OAuth2\Server\AbstractServer')->makePartial();
$repo = new FluentRefreshToken($this->app['db']);
$repo->setServer($server);
return $repo;
}
public function test_it_fetches_a_refresh_token_with_a_valid_token()
{
$repo = $this->getRefreshTokenRepository();
$result = $repo->get('totallyarefreshtoken1');
$this->assertInstanceOf('League\OAuth2\Server\Entity\RefreshTokenEntity', $result);
$this->assertEquals('totallyarefreshtoken1', $result->getId());
$this->assertInstanceOf('League\OAuth2\Server\Entity\AccessTokenEntity', $result->getAccessToken());
$this->assertEquals('totallyanaccesstoken1', $result->getAccessToken()->getId());
$this->assertInternalType('int', $result->getExpireTime());
}
public function test_it_returns_null_with_an_invalid_token()
{
$repo = $this->getRefreshTokenRepository();
$result = $repo->get('invalid_refresh_token');
$this->assertNull($result);
}
public function test_it_deletes_a_refresh_token()
{
$token = m::mock('League\OAuth2\Server\Entity\RefreshTokenEntity');
$token->shouldReceive('getId')->once()->andReturn('totallyarefreshtoken1');
$repo = $this->getRefreshTokenRepository();
$repo->delete($token);
$result = $repo->get('totallyarefreshtoken1');
$this->assertNull($result);
}
public function test_it_creates_a_refresh_token()
{
$repo = $this->getRefreshTokenRepository();
$time = time() + 120;
$result = $repo->create('newrefreshtoken', $time, 'totallyanaccesstoken2');
$this->assertInstanceOf('League\OAuth2\Server\Entity\RefreshTokenEntity', $result);
$this->assertEquals('newrefreshtoken', $result->getId());
$this->assertInstanceOf('League\OAuth2\Server\Entity\AccessTokenEntity', $result->getAccessToken());
$this->assertEquals('totallyanaccesstoken2', $result->getAccessToken()->getId());
$this->assertInternalType('int', $result->getExpireTime());
$this->assertEquals($time, $result->getExpireTime());
}
}