forked from saloonphp/saloon
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccessTokenAuthenticatorTest.php
More file actions
46 lines (34 loc) · 1.67 KB
/
AccessTokenAuthenticatorTest.php
File metadata and controls
46 lines (34 loc) · 1.67 KB
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
<?php
declare(strict_types=1);
use Saloon\Tests\Helpers\Date;
use Saloon\Http\Auth\AccessTokenAuthenticator;
it('can return if it has expired or not', function () {
$accessToken = 'access';
$refreshToken = 'refresh';
$expiresAt = Date::now()->subMinutes(5)->toDateTime();
$authenticator = new AccessTokenAuthenticator($accessToken, $refreshToken, $expiresAt);
expect($authenticator->isRefreshable())->toBeTrue();
expect($authenticator->isNotRefreshable())->toBeFalse();
expect($authenticator->hasExpired())->toBeTrue();
expect($authenticator->hasNotExpired())->toBeFalse();
});
test('can be constructed without a refresh token or expiry', function () {
$authenticator = new AccessTokenAuthenticator('access');
expect($authenticator->getAccessToken())->toEqual('access');
expect($authenticator->getRefreshToken())->toBeNull();
expect($authenticator->getExpiresAt())->toBeNull();
expect($authenticator->isRefreshable())->toBeFalse();
expect($authenticator->isNotRefreshable())->toBeTrue();
});
test('can be constructed with just an access token and expiry', function () {
$expiresAt = Date::now()->subMinutes(5)->toDateTime();
$authenticator = new AccessTokenAuthenticator('access', null, $expiresAt);
expect($authenticator->hasExpired())->toBeTrue();
expect($authenticator->hasNotExpired())->toBeFalse();
});
test('it allows expires_in to be optional', function () {
$authenticator = new AccessTokenAuthenticator('access', 'refresh', null);
expect($authenticator->getExpiresAt())->toBeNull();
expect($authenticator->isRefreshable())->toBeTrue();
expect($authenticator->isNotRefreshable())->toBeFalse();
});