Repository navigation
[FrameworkBundle] Inject the clock into comparison and range validators - #66683
Merged
nicolas-grekas merged 1 commit intoOct 7, 2026
Merged
Conversation
nicolas-grekas
force-pushed
the
fix/issue-66681-validator-clock
branch
from
October 7, 2026 14:02
aabc8a0 to
0cbd9cf
Compare
Member
|
Thank you @lazerg. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#63360 made the comparison validators and
RangeValidatoraccept a clock, and boundClockInterfaceon the validator prototype invalidator.php. That prototype is abstract and taggedcontainer.excluded, so it only exists for the translation extractor.AddConstraintValidatorsPassskips excluded services, the factory never finds these validators in its locator, and it builds them withnew $name(). The binding is never used, soMockClockandClockSensitiveTrait::mockTime()have no effect on bounds like'+48 hours'.This registers
RangeValidatorand the eight comparison validators as concrete services that getclock, the same wayvalidator.emailorvalidator.whenare registered. The property accessor argument staysnull, as it was withnew $name(). The dead binding is removed.DivisibleByValidatoralso extendsAbstractComparisonValidator, but relative dates make no sense there, so I left it out.The new test fails without the fix (1 violation instead of 0) and passes with it.
./phpunit src/Symfony/Bundle/FrameworkBundlepasses (1486 tests, 3 skipped).Merge-up to 8.2: the config moved to
src/Symfony/Component/Validator/Resources/config/validator.php, and git applies the change there. Only its imports conflict: keepConstantFunctionProviderand dropClockInterface.FrameworkExtensionTestCaseconflicts too: keep the 8.2 side and move the test toValidationBundleTest, where it needs no version check (with theMockClock,GreaterThan,LessThanandRangeimports):Checked on 8.2: the test fails without the change and passes with it.