|
14 | 14 | use Symfony\Component\Translation\IdentityTranslator;
|
15 | 15 | use Symfony\Component\Validator\Constraints\All;
|
16 | 16 | use Symfony\Component\Validator\Constraints\Collection;
|
| 17 | +use Symfony\Component\Validator\Constraints\GroupSequence; |
| 18 | +use Symfony\Component\Validator\Constraints\IsTrue; |
17 | 19 | use Symfony\Component\Validator\Constraints\Length;
|
18 | 20 | use Symfony\Component\Validator\Constraints\NotBlank;
|
| 21 | +use Symfony\Component\Validator\Constraints\NotNull; |
19 | 22 | use Symfony\Component\Validator\ConstraintValidatorFactory;
|
20 | 23 | use Symfony\Component\Validator\Context\ExecutionContextFactory;
|
| 24 | +use Symfony\Component\Validator\Mapping\ClassMetadata; |
21 | 25 | use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
|
22 | 26 | use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA;
|
23 | 27 | use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB;
|
24 | 28 | use Symfony\Component\Validator\Tests\Fixtures\Entity;
|
| 29 | +use Symfony\Component\Validator\Tests\Fixtures\EntityWithGroupedConstraintOnMethods; |
25 | 30 | use Symfony\Component\Validator\Validator\RecursiveValidator;
|
26 | 31 |
|
27 | 32 | class RecursiveValidatorTest extends AbstractTest
|
@@ -117,6 +122,25 @@ public function testCollectionConstraintValidateAllGroupsForNestedConstraints()
|
117 | 122 | $this->assertInstanceOf(NotBlank::class, $violations->get(1)->getConstraint());
|
118 | 123 | }
|
119 | 124 |
|
| 125 | + public function testGroupedMethodConstraintValidateInSequence() |
| 126 | + { |
| 127 | + $metadata = new ClassMetadata(EntityWithGroupedConstraintOnMethods::class); |
| 128 | + $metadata->addPropertyConstraint('bar', new NotNull(['groups' => 'Foo'])); |
| 129 | + $metadata->addGetterMethodConstraint('validInFoo', 'isValidInFoo', new IsTrue(['groups' => 'Foo'])); |
| 130 | + $metadata->addGetterMethodConstraint('bar', 'getBar', new NotNull(['groups' => 'Bar'])); |
| 131 | + |
| 132 | + $this->metadataFactory->addMetadata($metadata); |
| 133 | + |
| 134 | + $entity = new EntityWithGroupedConstraintOnMethods(); |
| 135 | + $groups = new GroupSequence(['EntityWithGroupedConstraintOnMethods', 'Foo', 'Bar']); |
| 136 | + |
| 137 | + $violations = $this->validator->validate($entity, null, $groups); |
| 138 | + |
| 139 | + $this->assertCount(2, $violations); |
| 140 | + $this->assertInstanceOf(NotNull::class, $violations->get(0)->getConstraint()); |
| 141 | + $this->assertInstanceOf(IsTrue::class, $violations->get(1)->getConstraint()); |
| 142 | + } |
| 143 | + |
120 | 144 | public function testAllConstraintValidateAllGroupsForNestedConstraints()
|
121 | 145 | {
|
122 | 146 | $this->metadata->addPropertyConstraint('data', new All(['constraints' => [
|
|
0 commit comments