1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of graze/gigya-client |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @license https://github.com/graze/gigya-client/blob/master/LICENSE.md |
11
|
|
|
* @link https://github.com/graze/gigya-client |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Graze\Gigya\Test\Unit\Auth\OAuth2; |
15
|
|
|
|
16
|
|
|
use DateInterval; |
17
|
|
|
use DateTime; |
18
|
|
|
use Graze\Gigya\Auth\OAuth2\AccessToken; |
19
|
|
|
use Graze\Gigya\Test\TestCase; |
20
|
|
|
|
21
|
|
|
class AccessTokenTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testTokenWithNoExpiryIsNeverExpired() |
24
|
|
|
{ |
25
|
|
|
$token = new AccessToken('token'); |
26
|
|
|
static::assertEquals('token', $token->getToken()); |
27
|
|
|
static::assertNull($token->getExpires()); |
28
|
|
|
static::assertFalse($token->isExpired()); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function testTokenWithExpiryIsShown() |
32
|
|
|
{ |
33
|
|
|
$expires = (new DateTime())->add(new DateInterval('PT60S')); |
34
|
|
|
$token = new AccessToken('token', $expires); |
35
|
|
|
static::assertEquals('token', $token->getToken()); |
36
|
|
|
static::assertLessThanOrEqual($expires, $token->getExpires()); |
37
|
|
|
static::assertFalse($token->isExpired()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testTokenWithExpiryAsNowIsExpired() |
41
|
|
|
{ |
42
|
|
|
$expires = new DateTime(); |
43
|
|
|
$token = new AccessToken('token', $expires); |
44
|
|
|
static::assertEquals('token', $token->getToken()); |
45
|
|
|
static::assertLessThanOrEqual($expires, $token->getExpires()); |
46
|
|
|
static::assertTrue($token->isExpired()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testProperties() |
50
|
|
|
{ |
51
|
|
|
$token = new AccessToken('token'); |
52
|
|
|
static::assertEquals('token', $token->getToken()); |
53
|
|
|
static::assertNull($token->getExpires()); |
54
|
|
|
static::assertFalse($token->isExpired()); |
55
|
|
|
|
56
|
|
|
$token->setToken('new token'); |
57
|
|
|
static::assertEquals('new token', $token->getToken()); |
58
|
|
|
|
59
|
|
|
$expires = (new DateTime())->add(new DateInterval('PT60S')); |
60
|
|
|
|
61
|
|
|
$token->setExpires($expires); |
62
|
|
|
static::assertEquals($expires, $token->getExpires()); |
63
|
|
|
static::assertFalse($token->isExpired()); |
64
|
|
|
|
65
|
|
|
$expires = new DateTime(); |
66
|
|
|
$token->setExpires($expires); |
67
|
|
|
static::assertTrue($token->isExpired()); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|