Skip to content

Use symfony/clock component when available instead of non-testable time()#1204

Merged
chalasr merged 1 commit intolexik:3.xfrom
Dean151:symfony-clock
Feb 15, 2026
Merged

Use symfony/clock component when available instead of non-testable time()#1204
chalasr merged 1 commit intolexik:3.xfrom
Dean151:symfony-clock

Conversation

@Dean151
Copy link
Contributor

@Dean151 Dean151 commented Feb 10, 2024

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.

@Dean151
Copy link
Contributor Author

Dean151 commented Feb 10, 2024

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

@chalasr
Copy link
Collaborator

chalasr commented Dec 14, 2024

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)

@Dean151
Copy link
Contributor Author

Dean151 commented Dec 16, 2024

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
@Dean151 Dean151 changed the base branch from 2.x to 3.x February 15, 2026 18:13
@Dean151
Copy link
Contributor Author

Dean151 commented Feb 15, 2026

Hello @chalasr !
In your own time, of course, just be aware that I rebased my PR to target 3.x branch, and took advantage of the removal of lcobucci/clock to simplify the code change.

With my best sentiments!

@chalasr
Copy link
Collaborator

chalasr commented Feb 15, 2026

It took time, but here we go, this is in now. Thank you very much @Dean151.

@chalasr chalasr merged commit 15324dc into lexik:3.x Feb 15, 2026
9 checks passed
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