Skip to content

Commit 3c8c2b4

Browse files
prikkprikkprikkramsey
authored andcommitted
hasExpired() should use self::getTimeNow()
1 parent 2d06e3e commit 3c8c2b4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/Token/AccessToken.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public function hasExpired()
204204
throw new RuntimeException('"expires" is not set on the token');
205205
}
206206

207-
return $expires < time();
207+
return $expires < $this->getTimeNow();
208208
}
209209

210210
/**

test/src/Token/AccessTokenTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ public function testHasExpiredWhenPropertySetInPast()
178178
self::tearDownForBackwardsCompatibility();
179179
}
180180

181+
public function testHasExpiredWhenTimeNowIsInFuture()
182+
{
183+
$options = [
184+
'access_token' => 'mock_access_token',
185+
'expires' => time(),
186+
];
187+
188+
$token = $this->getAccessToken($options);
189+
190+
$token->setTimeNow(time() + 60);
191+
192+
$this->assertTrue($token->hasExpired());
193+
194+
self::tearDownForBackwardsCompatibility();
195+
}
196+
181197
public function testCannotReportExpiredWhenNoExpirationSet()
182198
{
183199
$options = [

0 commit comments

Comments
 (0)