Skip to content

Commit ff8603b

Browse files
committed
propagate groups to nested constraints
1 parent bc92bba commit ff8603b

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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;

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 <[email protected]>
@@ -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)