Skip to content

Commit 929b4b5

Browse files
bug #39649 [Validator] propagate groups to nested constraints (xabbuh)
This PR was merged into the 5.1 branch. Discussion ---------- [Validator] propagate groups to nested constraints | Q | A | ------------- | --- | Branch? | 5.1 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #39386 | License | MIT | Doc PR | Commits ------- 13a4610 propagate groups to nested constraints
2 parents 87b1e11 + 13a4610 commit 929b4b5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Symfony/Component/Validator/Constraints/AtLeastOneOfValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function validate($value, Constraint $constraint)
3434
$messages = [$constraint->message];
3535

3636
foreach ($constraint->constraints as $key => $item) {
37-
$violations = $validator->validate($value, $item);
37+
$violations = $validator->validate($value, $item, $this->context->getGroup());
3838

3939
if (0 === \count($violations)) {
4040
return;

src/Symfony/Component/Validator/Tests/Constraints/AtLeastOneOfValidatorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Symfony\Component\Validator\Constraints\Regex;
2929
use Symfony\Component\Validator\Constraints\Unique;
3030
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
31+
use Symfony\Component\Validator\Validation;
3132

3233
/**
3334
* @author Przemysław Bogusz <przemyslaw.bogusz@tubotax.pl>
@@ -160,4 +161,27 @@ public function getInvalidCombinations()
160161
]],
161162
];
162163
}
164+
165+
public function testGroupsArePropagatedToNestedConstraints()
166+
{
167+
$validator = Validation::createValidator();
168+
169+
$violations = $validator->validate(50, new AtLeastOneOf([
170+
'constraints' => [
171+
new Range([
172+
'groups' => 'non_default_group',
173+
'min' => 10,
174+
'max' => 20,
175+
]),
176+
new Range([
177+
'groups' => 'non_default_group',
178+
'min' => 30,
179+
'max' => 40,
180+
]),
181+
],
182+
'groups' => 'non_default_group',
183+
]), 'non_default_group');
184+
185+
$this->assertCount(1, $violations);
186+
}
163187
}

0 commit comments

Comments
 (0)