Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hasExpired() should use self::getTimeNow() #993

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Token/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public function hasExpired()
throw new RuntimeException('"expires" is not set on the token');
}

return $expires < time();
return $expires < self::getTimeNow();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be $this->getTimeNow(), since getTimeNow() is an instance method and not a static method?

Copy link
Author

@prikkprikkprikk prikkprikkprikk Apr 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I missed that—probably because the accompanying setTimeNow() and resetTimeNow() are static methods.

Maybe getTimeNow() should be a static method too instead? It does not reference any instance-specific properties, only self::timeNow, or time() if self::timeNow is not set, so I can't see a good reason to have it as an instance method.

I have done that in my local development repo, and all tests are still passing. Will commit if I get a thumb up.

}

/**
Expand Down
16 changes: 16 additions & 0 deletions test/src/Token/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,22 @@ public function testHasExpiredWhenPropertySetInPast()
self::tearDownForBackwardsCompatibility();
}

public function testHasExpiredWhenTimeNowIsInFuture()
{
$options = [
'access_token' => 'mock_access_token',
'expires' => time(),
];

$token = $this->getAccessToken($options);

$token->setTimeNow(time() + 60);

$this->assertTrue($token->hasExpired());

self::tearDownForBackwardsCompatibility();
}

public function testCannotReportExpiredWhenNoExpirationSet()
{
$options = [
Expand Down