|
20 | 20 | use Symfony\Component\Validator\Constraints\Length;
|
21 | 21 | use Symfony\Component\Validator\Constraints\NotBlank;
|
22 | 22 | use Symfony\Component\Validator\Constraints\NotNull;
|
| 23 | +use Symfony\Component\Validator\Constraints\StrictTypes; |
23 | 24 | use Symfony\Component\Validator\Constraints\Type;
|
24 | 25 | use Symfony\Component\Validator\Constraints\Valid;
|
25 | 26 | use Symfony\Component\Validator\ConstraintValidatorFactory;
|
@@ -276,4 +277,46 @@ public function testValidateWithExplicitCascade()
|
276 | 277 |
|
277 | 278 | CascadingEntity::$staticChild = null;
|
278 | 279 | }
|
| 280 | + |
| 281 | + /** |
| 282 | + * @requires PHP 7.4 |
| 283 | + */ |
| 284 | + public function testValidateWithExplicitCascadeUninitialized() |
| 285 | + { |
| 286 | + $this->metadataFactory->addMetadata((new ClassMetadata(CascadingEntity::class)) |
| 287 | + ->addConstraint(new Cascade()) |
| 288 | + ); |
| 289 | + $this->metadataFactory->addMetadata((new ClassMetadata(CascadedChild::class)) |
| 290 | + ->addPropertyConstraint('name', new NotNull()) |
| 291 | + ); |
| 292 | + |
| 293 | + $entity = new CascadingEntity(); |
| 294 | + |
| 295 | + $violations = $this->validator->validate($entity); |
| 296 | + |
| 297 | + $this->assertCount(0, $violations); |
| 298 | + } |
| 299 | + |
| 300 | + /** |
| 301 | + * @requires PHP 7.4 |
| 302 | + */ |
| 303 | + public function testValidateWithExplicitStrictTypesUninitialized() |
| 304 | + { |
| 305 | + $this->metadataFactory->addMetadata((new ClassMetadata(CascadingEntity::class)) |
| 306 | + ->addConstraint(new StrictTypes()) |
| 307 | + ); |
| 308 | + |
| 309 | + $entity = new CascadingEntity(); |
| 310 | + |
| 311 | + $violations = $this->validator->validate($entity); |
| 312 | + |
| 313 | + $this->assertCount(3, $violations); |
| 314 | + |
| 315 | + $this->assertInstanceOf(NotNull::class, $violations->get(0)->getConstraint()); |
| 316 | + $this->assertInstanceOf(NotNull::class, $violations->get(1)->getConstraint()); |
| 317 | + $this->assertInstanceOf(NotNull::class, $violations->get(2)->getConstraint()); |
| 318 | + $this->assertSame('scalar', $violations->get(0)->getPropertyPath()); |
| 319 | + $this->assertSame('requiredChild', $violations->get(1)->getPropertyPath()); |
| 320 | + $this->assertSame('children', $violations->get(2)->getPropertyPath()); |
| 321 | + } |
279 | 322 | }
|
0 commit comments