|
13 | 13 |
|
14 | 14 | use PHPUnit\Framework\TestCase; |
15 | 15 | use Symfony\Component\Translation\IdentityTranslator; |
| 16 | +use Symfony\Component\Validator\Constraint; |
16 | 17 | use Symfony\Component\Validator\Constraints\All; |
17 | 18 | use Symfony\Component\Validator\Constraints\Callback; |
18 | 19 | use Symfony\Component\Validator\Constraints\Collection; |
19 | 20 | use Symfony\Component\Validator\Constraints\Expression; |
20 | 21 | use Symfony\Component\Validator\Constraints\GroupSequence; |
| 22 | +use Symfony\Component\Validator\Constraints\IsFalse; |
| 23 | +use Symfony\Component\Validator\Constraints\IsNull; |
21 | 24 | use Symfony\Component\Validator\Constraints\IsTrue; |
22 | 25 | use Symfony\Component\Validator\Constraints\Length; |
23 | 26 | use Symfony\Component\Validator\Constraints\NotBlank; |
|
26 | 29 | use Symfony\Component\Validator\Constraints\Required; |
27 | 30 | use Symfony\Component\Validator\Constraints\Traverse; |
28 | 31 | use Symfony\Component\Validator\Constraints\Valid; |
| 32 | +use Symfony\Component\Validator\ConstraintValidator; |
29 | 33 | use Symfony\Component\Validator\ConstraintValidatorFactory; |
30 | 34 | use Symfony\Component\Validator\ConstraintViolationInterface; |
31 | 35 | use Symfony\Component\Validator\Context\ExecutionContextFactory; |
@@ -2135,4 +2139,47 @@ public function testOptionalConstraintIsIgnored() |
2135 | 2139 |
|
2136 | 2140 | $this->assertCount(0, $violations); |
2137 | 2141 | } |
| 2142 | + |
| 2143 | + public function testValidatedConstraintsHashesDoNotCollide() |
| 2144 | + { |
| 2145 | + $metadata = new ClassMetadata(Entity::class); |
| 2146 | + $metadata->addPropertyConstraint('initialized', new NotNull(['groups' => 'should_pass'])); |
| 2147 | + $metadata->addPropertyConstraint('initialized', new IsNull(['groups' => 'should_fail'])); |
| 2148 | + |
| 2149 | + $this->metadataFactory->addMetadata($metadata); |
| 2150 | + |
| 2151 | + $entity = new Entity(); |
| 2152 | + $entity->data = new \stdClass(); |
| 2153 | + |
| 2154 | + $this->assertCount(2, $this->validator->validate($entity, new TestConstraintHashesDoNotCollide())); |
| 2155 | + } |
| 2156 | +} |
| 2157 | + |
| 2158 | +final class TestConstraintHashesDoNotCollide extends Constraint |
| 2159 | +{ |
| 2160 | +} |
| 2161 | + |
| 2162 | +final class TestConstraintHashesDoNotCollideValidator extends ConstraintValidator |
| 2163 | +{ |
| 2164 | + /** |
| 2165 | + * {@inheritdoc} |
| 2166 | + */ |
| 2167 | + public function validate($value, Constraint $constraint) |
| 2168 | + { |
| 2169 | + if (!$value instanceof Entity) { |
| 2170 | + throw new \LogicException(); |
| 2171 | + } |
| 2172 | + |
| 2173 | + $this->context->getValidator() |
| 2174 | + ->inContext($this->context) |
| 2175 | + ->atPath('data') |
| 2176 | + ->validate($value, new NotNull()) |
| 2177 | + ->validate($value, new NotNull()) |
| 2178 | + ->validate($value, new IsFalse()); |
| 2179 | + |
| 2180 | + $this->context->getValidator() |
| 2181 | + ->inContext($this->context) |
| 2182 | + ->validate($value, null, new GroupSequence(['should_pass'])) |
| 2183 | + ->validate($value, null, new GroupSequence(['should_fail'])); |
| 2184 | + } |
2138 | 2185 | } |
0 commit comments