Use symfony/clock component when available instead of non-testable time()#1204
Use symfony/clock component when available instead of non-testable time()#1204
Conversation
|
Sadly, this might be incompatible with:
Therefore, I do think the dependency should be flexible in the source, and we could use the one we prefer in the tests so that the end user can rely on whatever psr/clock implementation he prefers |
|
Apologies for being one year late here. I would like to replace lcobucci/clock by symfony/clock and have symfony/clock as dev-dependency. The former requires to add some backward compatibility layers. Once done I'll merge your PR (without the class-exists checks) |
No need to apologize! Open-source isn’t a full-time job, and I truly appreciate the time you spend maintaining, testing, and reviewing. Thank you! 😊 |
…me() # Conflicts: # Services/JWSProvider/DefaultJWSProvider.php # Services/JWSProvider/LcobucciJWSProvider.php # Signature/LoadedJWS.php # composer.json
097fb89 to
a011829
Compare
|
Hello @chalasr ! With my best sentiments! |
|
It took time, but here we go, this is in now. Thank you very much @Dean151. |
Motivation:
Tests are already hard enough to build so that they are testing, covering, isolated and in an expected way.
Therefore, managing external dependencies is an obligation. And time is an external dependency.
With the introduction of symfony/clock in 6.3, Symfony proposes a solution for managing time in an application, with a shared instance that is overridable during the tests.
Now that the library requires it as a dependencies, we can use it everywhere it should be used in place of php native methods.
Solution:
This PR looked over the time() usage, and replaced them with Symfony's
Clock::now()->getTimeStamp()when available.Retro-compatibility:
This behavior change is probably what the user would expect from a library having symfony/clock as a requirement ; so they probably are fine.
Tests:
Current test suite still uses time(), but they could be improved to take advantage of this new testability.