|
21 | 21 | use Symfony\Component\Validator\Constraints\NotNull; |
22 | 22 | use Symfony\Component\Validator\Constraints\Optional; |
23 | 23 | use Symfony\Component\Validator\Constraints\Required; |
| 24 | +use Symfony\Component\Validator\Constraints\Valid; |
24 | 25 | use Symfony\Component\Validator\ConstraintValidatorFactory; |
25 | 26 | use Symfony\Component\Validator\Context\ExecutionContextFactory; |
26 | 27 | use Symfony\Component\Validator\Mapping\ClassMetadata; |
27 | 28 | use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; |
28 | 29 | use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA; |
29 | 30 | use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB; |
30 | 31 | use Symfony\Component\Validator\Tests\Fixtures\Entity; |
| 32 | +use Symfony\Component\Validator\Tests\Fixtures\EntityParent; |
31 | 33 | use Symfony\Component\Validator\Tests\Fixtures\EntityWithGroupedConstraintOnMethods; |
32 | 34 | use Symfony\Component\Validator\Validator\RecursiveValidator; |
33 | 35 |
|
@@ -143,6 +145,31 @@ public function testGroupedMethodConstraintValidateInSequence() |
143 | 145 | $this->assertInstanceOf(IsTrue::class, $violations->get(1)->getConstraint()); |
144 | 146 | } |
145 | 147 |
|
| 148 | + public function testValidConstraintOnGetterReturningNull() |
| 149 | + { |
| 150 | + $metadata = new ClassMetadata(EntityParent::class); |
| 151 | + $metadata->addGetterConstraint('child', new Valid()); |
| 152 | + |
| 153 | + $this->metadataFactory->addMetadata($metadata); |
| 154 | + |
| 155 | + $violations = $this->validator->validate(new EntityParent()); |
| 156 | + |
| 157 | + $this->assertCount(0, $violations); |
| 158 | + } |
| 159 | + |
| 160 | + public function testNotNullConstraintOnGetterReturningNull() |
| 161 | + { |
| 162 | + $metadata = new ClassMetadata(EntityParent::class); |
| 163 | + $metadata->addGetterConstraint('child', new NotNull()); |
| 164 | + |
| 165 | + $this->metadataFactory->addMetadata($metadata); |
| 166 | + |
| 167 | + $violations = $this->validator->validate(new EntityParent()); |
| 168 | + |
| 169 | + $this->assertCount(1, $violations); |
| 170 | + $this->assertInstanceOf(NotNull::class, $violations->get(0)->getConstraint()); |
| 171 | + } |
| 172 | + |
146 | 173 | public function testAllConstraintValidateAllGroupsForNestedConstraints() |
147 | 174 | { |
148 | 175 | $this->metadata->addPropertyConstraint('data', new All(['constraints' => [ |
|
0 commit comments