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