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

Conversation

prikkprikkprikk
Copy link

While trying to test some code that caches an AccessToken and refreshes it if it has expired, I discovered that AccessToken->hasExpired() uses time() instead of self::getTimeNow(), and thus ignores self::$timeNow when testing.

This pull request fixes that.

@codecov
Copy link

codecov bot commented Apr 16, 2023

Codecov Report

Merging #993 (4884dea) into master (164ccb0) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##              master      #993   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       190       190           
===========================================
  Files             20        20           
  Lines            514       514           
===========================================
  Hits             514       514           
Impacted Files Coverage Δ
src/Token/AccessToken.php 100.00% <100.00%> (ø)

@@ -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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants