|
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 | use Symfony\Component\Validator\Validator\ValidatorInterface;
|
@@ -144,6 +146,31 @@ public function testGroupedMethodConstraintValidateInSequence()
|
144 | 146 | $this->assertInstanceOf(IsTrue::class, $violations->get(1)->getConstraint());
|
145 | 147 | }
|
146 | 148 |
|
| 149 | + public function testValidConstraintOnGetterReturningNull() |
| 150 | + { |
| 151 | + $metadata = new ClassMetadata(EntityParent::class); |
| 152 | + $metadata->addGetterConstraint('child', new Valid()); |
| 153 | + |
| 154 | + $this->metadataFactory->addMetadata($metadata); |
| 155 | + |
| 156 | + $violations = $this->validator->validate(new EntityParent()); |
| 157 | + |
| 158 | + $this->assertCount(0, $violations); |
| 159 | + } |
| 160 | + |
| 161 | + public function testNotNullConstraintOnGetterReturningNull() |
| 162 | + { |
| 163 | + $metadata = new ClassMetadata(EntityParent::class); |
| 164 | + $metadata->addGetterConstraint('child', new NotNull()); |
| 165 | + |
| 166 | + $this->metadataFactory->addMetadata($metadata); |
| 167 | + |
| 168 | + $violations = $this->validator->validate(new EntityParent()); |
| 169 | + |
| 170 | + $this->assertCount(1, $violations); |
| 171 | + $this->assertInstanceOf(NotNull::class, $violations->get(0)->getConstraint()); |
| 172 | + } |
| 173 | + |
147 | 174 | public function testAllConstraintValidateAllGroupsForNestedConstraints()
|
148 | 175 | {
|
149 | 176 | $this->metadata->addPropertyConstraint('data', new All(['constraints' => [
|
|
0 commit comments