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

Closed
wants to merge 4 commits into from

Conversation

prikkprikkprikk
Copy link
Contributor

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

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (2455200) to head (524fc15).
Report is 25 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##              master      #993   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       191       193    +2     
===========================================
  Files             20        20           
  Lines            516       521    +5     
===========================================
+ Hits             516       521    +5     
Files with missing lines 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
Contributor 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.

@ramsey
Copy link
Contributor

ramsey commented Dec 11, 2024

Merged to the master branch in 3c8c2b4

Thank you for contributing! 🎉

@ramsey ramsey closed this Dec 11, 2024
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.

2 participants