|
14 | 14 | use Symfony\Component\Validator\Constraints\AtLeastOneOf; |
15 | 15 | use Symfony\Component\Validator\Constraints\AtLeastOneOfValidator; |
16 | 16 | use Symfony\Component\Validator\Constraints\Choice; |
| 17 | +use Symfony\Component\Validator\Constraints\Collection; |
17 | 18 | use Symfony\Component\Validator\Constraints\Count; |
18 | 19 | use Symfony\Component\Validator\Constraints\Country; |
19 | 20 | use Symfony\Component\Validator\Constraints\DivisibleBy; |
|
27 | 28 | use Symfony\Component\Validator\Constraints\Length; |
28 | 29 | use Symfony\Component\Validator\Constraints\LessThan; |
29 | 30 | use Symfony\Component\Validator\Constraints\Negative; |
| 31 | +use Symfony\Component\Validator\Constraints\NotBlank; |
30 | 32 | use Symfony\Component\Validator\Constraints\NotNull; |
31 | 33 | use Symfony\Component\Validator\Constraints\Range; |
32 | 34 | use Symfony\Component\Validator\Constraints\Regex; |
| 35 | +use Symfony\Component\Validator\Constraints\Type; |
33 | 36 | use Symfony\Component\Validator\Constraints\Unique; |
34 | 37 | use Symfony\Component\Validator\Constraints\Valid; |
35 | 38 | use Symfony\Component\Validator\ConstraintViolation; |
@@ -296,6 +299,35 @@ public function trans(?string $id, array $parameters = [], ?string $domain = nul |
296 | 299 | $this->assertCount(1, $violations); |
297 | 300 | $this->assertSame('Dummy translation: [1] Dummy violation.', $violations->get(0)->getMessage()); |
298 | 301 | } |
| 302 | + |
| 303 | + public function testValidateNestedAtLeaseOneOfConstraints() |
| 304 | + { |
| 305 | + $data = [ |
| 306 | + 'foo' => [ |
| 307 | + 'bar' => 'foo.bar', |
| 308 | + 'baz' => 'foo.baz', |
| 309 | + ], |
| 310 | + ]; |
| 311 | + |
| 312 | + $constraints = new Collection([ |
| 313 | + 'foo' => new AtLeastOneOf([ |
| 314 | + new Collection([ |
| 315 | + 'bar' => new AtLeastOneOf([ |
| 316 | + new Type('int'), |
| 317 | + new Choice(['test1', 'test2']) |
| 318 | + ]), |
| 319 | + ]), |
| 320 | + new Collection([ |
| 321 | + 'baz' => new Type('int'), |
| 322 | + ]), |
| 323 | + ]), |
| 324 | + ]); |
| 325 | + |
| 326 | + $validator = Validation::createValidator(); |
| 327 | + $violations = $validator->validate($data, $constraints); |
| 328 | + |
| 329 | + self::assertCount(1, $violations); |
| 330 | + } |
299 | 331 | } |
300 | 332 |
|
301 | 333 | class ExpressionConstraintNested |
|
0 commit comments