|
12 | 12 | namespace Symfony\Component\Validator\Tests\Validator;
|
13 | 13 |
|
14 | 14 | use Symfony\Component\Translation\IdentityTranslator;
|
| 15 | +use Symfony\Component\Validator\Constraint; |
15 | 16 | use Symfony\Component\Validator\Constraints\All;
|
16 | 17 | use Symfony\Component\Validator\Constraints\Collection;
|
17 | 18 | use Symfony\Component\Validator\Constraints\GroupSequence;
|
| 19 | +use Symfony\Component\Validator\Constraints\IsFalse; |
| 20 | +use Symfony\Component\Validator\Constraints\IsNull; |
18 | 21 | use Symfony\Component\Validator\Constraints\IsTrue;
|
19 | 22 | use Symfony\Component\Validator\Constraints\Length;
|
20 | 23 | use Symfony\Component\Validator\Constraints\NotBlank;
|
21 | 24 | use Symfony\Component\Validator\Constraints\NotNull;
|
22 | 25 | use Symfony\Component\Validator\Constraints\Optional;
|
23 | 26 | use Symfony\Component\Validator\Constraints\Required;
|
24 | 27 | use Symfony\Component\Validator\Constraints\Valid;
|
| 28 | +use Symfony\Component\Validator\ConstraintValidator; |
25 | 29 | use Symfony\Component\Validator\ConstraintValidatorFactory;
|
26 | 30 | use Symfony\Component\Validator\Context\ExecutionContextFactory;
|
27 | 31 | use Symfony\Component\Validator\Mapping\ClassMetadata;
|
@@ -200,4 +204,47 @@ public function testOptionalConstraintIsIgnored()
|
200 | 204 |
|
201 | 205 | $this->assertCount(0, $violations);
|
202 | 206 | }
|
| 207 | + |
| 208 | + public function testValidatedConstraintsHashesDontCollide() |
| 209 | + { |
| 210 | + $metadata = new ClassMetadata(Entity::class); |
| 211 | + $metadata->addPropertyConstraint('initialized', new NotNull(['groups' => 'should_pass'])); |
| 212 | + $metadata->addPropertyConstraint('initialized', new IsNull(['groups' => 'should_fail'])); |
| 213 | + |
| 214 | + $this->metadataFactory->addMetadata($metadata); |
| 215 | + |
| 216 | + $entity = new Entity(); |
| 217 | + $entity->data = new \stdClass(); |
| 218 | + |
| 219 | + $this->assertCount(2, $this->validator->validate($entity, new TestConstraintHashesDontCollide())); |
| 220 | + } |
| 221 | +} |
| 222 | + |
| 223 | +final class TestConstraintHashesDontCollide extends Constraint |
| 224 | +{ |
| 225 | +} |
| 226 | + |
| 227 | +final class TestConstraintHashesDontCollideValidator extends ConstraintValidator |
| 228 | +{ |
| 229 | + /** |
| 230 | + * {@inheritdoc} |
| 231 | + */ |
| 232 | + public function validate($value, Constraint $constraint) |
| 233 | + { |
| 234 | + if (!$value instanceof Entity) { |
| 235 | + throw new \LogicException(); |
| 236 | + } |
| 237 | + |
| 238 | + $this->context->getValidator() |
| 239 | + ->inContext($this->context) |
| 240 | + ->atPath('data') |
| 241 | + ->validate($value, new NotNull()) |
| 242 | + ->validate($value, new NotNull()) |
| 243 | + ->validate($value, new IsFalse()); |
| 244 | + |
| 245 | + $this->context->getValidator() |
| 246 | + ->inContext($this->context) |
| 247 | + ->validate($value, null, new GroupSequence(['should_pass'])) |
| 248 | + ->validate($value, null, new GroupSequence(['should_fail'])); |
| 249 | + } |
203 | 250 | }
|
0 commit comments