propagate groups to nested constraints
This commit is contained in:
parent
29b41edf06
commit
13a4610824
@ -34,7 +34,7 @@ class AtLeastOneOfValidator extends ConstraintValidator
|
||||
$messages = [$constraint->message];
|
||||
|
||||
foreach ($constraint->constraints as $key => $item) {
|
||||
$violations = $validator->validate($value, $item);
|
||||
$violations = $validator->validate($value, $item, $this->context->getGroup());
|
||||
|
||||
if (0 === \count($violations)) {
|
||||
return;
|
||||
|
@ -28,6 +28,7 @@ use Symfony\Component\Validator\Constraints\Range;
|
||||
use Symfony\Component\Validator\Constraints\Regex;
|
||||
use Symfony\Component\Validator\Constraints\Unique;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
/**
|
||||
* @author Przemysław Bogusz <przemyslaw.bogusz@tubotax.pl>
|
||||
@ -160,4 +161,27 @@ class AtLeastOneOfValidatorTest extends ConstraintValidatorTestCase
|
||||
]],
|
||||
];
|
||||
}
|
||||
|
||||
public function testGroupsArePropagatedToNestedConstraints()
|
||||
{
|
||||
$validator = Validation::createValidator();
|
||||
|
||||
$violations = $validator->validate(50, new AtLeastOneOf([
|
||||
'constraints' => [
|
||||
new Range([
|
||||
'groups' => 'non_default_group',
|
||||
'min' => 10,
|
||||
'max' => 20,
|
||||
]),
|
||||
new Range([
|
||||
'groups' => 'non_default_group',
|
||||
'min' => 30,
|
||||
'max' => 40,
|
||||
]),
|
||||
],
|
||||
'groups' => 'non_default_group',
|
||||
]), 'non_default_group');
|
||||
|
||||
$this->assertCount(1, $violations);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user