-
Notifications
You must be signed in to change notification settings - Fork 752
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
Allow time to be set for test purposes #852
Conversation
This just adds a static method for test purposes so that downstream code can more easily assert an exact `AccessToken` object in their tests. Since the calls to `time()` are non-deterministic, downstream tests are forced to mock, or do looser assertions on the `expires` property.
And write a few more tests around new method
@ramsey I had forgotten about this PR, but I got the notification master had been merged in, so I checked it and noticed that there was a CI failure due to But fixing this makes the php 5.6 run fail. Seems like whack-a-mole. What's the solution here? |
I dealt with the same thing getting tests to run on 5.6 through 8.0. The solution is to code around |
wack-a-mole complete lol 🔨 |
Thanks! |
@ramsey FWIW there is a strategy that Symfony and Drupal have been using to overcome PHP compatibility issues when trying to support PHP5 + newer versions of PHPunit: On test bootstrap, actually modify the test files on disk and remove the return types: |
This adds two new interfaces: - `ClockInterface` This is basically the spec from https://github.com/php-fig/fig-standards/blob/master/proposed/clock.md except without a return typehint to support PHP 5.6 for now - `ClockAwareInterface` - this may not be necessary but it seemed reasonable to have a `getClock(): ClockInterface` contract, given that we expect to be able to get a clock in both `AccessToken` and `AbstractProvider`. This also removes some methods added in thephpleague#852, specifically: - `AccessToken::setTimeNow()` - `AccessToken::getTimeNow()` - `AccessToken::resetTimeNow()` - `AccessToken::$timeNow` That technically represents a BC break, but: 1. That code has not existed for very long and likely has very little usage. 2. This *should* only break test code unless someone was doing something very strange in production. For the existing `AccessTokenInterface`: - remove the `setClock()` and `getTimeNow()` - `getTimeNow()` is no longer needed anyway - `setClock()` better not to have a setter on an interface in this case - both of these changes were BC breaks so they were removed I believe the rest of the changes here are just cleaning up tests that used the older static method of setting the current time. The previous hack `tearDownForBackwardsCompatibility()` is no longer needed so it was removed.
This just adds a static method for test purposes so that downstream code can more easily assert an exact
AccessToken
object in their tests.Since the calls to
time()
are non-deterministic, downstream tests are forced to mock, or do looser assertions on theexpires
property.Usage might be something like this:
I did this because I was writing some tests around code that depends on this library, and it seemed useful to me, however I understand if using static methods for test purposes is something you prefer not to do, or it otherwise doesn't fit with the coding preferences here.