Skip to content

Commit

Permalink
Merge branch '3.4' into 4.4
Browse files Browse the repository at this point in the history
* 3.4:
  [ErrorHandler] fix throwing from __toString()
  Removed comments and requirements relative to php <5.5 (not supported anymore)
  fix validating lazy properties that evaluate to null
  • Loading branch information
nicolas-grekas committed Jun 30, 2020
2 parents d7d79aa + 008b418 commit f2b1e1d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Tests/Fixtures/EntityParent.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class EntityParent implements EntityInterfaceA
protected $firstName;
private $internal;
private $data = 'Data';
private $child;

/**
* @NotNull
Expand All @@ -28,4 +29,9 @@ public function getData()
{
return 'Data';
}

public function getChild()
{
return $this->child;
}
}
27 changes: 27 additions & 0 deletions Tests/Validator/RecursiveValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
use Symfony\Component\Validator\Constraints\NotNull;
use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Constraints\Required;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\ConstraintValidatorFactory;
use Symfony\Component\Validator\Context\ExecutionContextFactory;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface;
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildA;
use Symfony\Component\Validator\Tests\Constraints\Fixtures\ChildB;
use Symfony\Component\Validator\Tests\Fixtures\Entity;
use Symfony\Component\Validator\Tests\Fixtures\EntityParent;
use Symfony\Component\Validator\Tests\Fixtures\EntityWithGroupedConstraintOnMethods;
use Symfony\Component\Validator\Validator\RecursiveValidator;
use Symfony\Component\Validator\Validator\ValidatorInterface;
Expand Down Expand Up @@ -144,6 +146,31 @@ public function testGroupedMethodConstraintValidateInSequence()
$this->assertInstanceOf(IsTrue::class, $violations->get(1)->getConstraint());
}

public function testValidConstraintOnGetterReturningNull()
{
$metadata = new ClassMetadata(EntityParent::class);
$metadata->addGetterConstraint('child', new Valid());

$this->metadataFactory->addMetadata($metadata);

$violations = $this->validator->validate(new EntityParent());

$this->assertCount(0, $violations);
}

public function testNotNullConstraintOnGetterReturningNull()
{
$metadata = new ClassMetadata(EntityParent::class);
$metadata->addGetterConstraint('child', new NotNull());

$this->metadataFactory->addMetadata($metadata);

$violations = $this->validator->validate(new EntityParent());

$this->assertCount(1, $violations);
$this->assertInstanceOf(NotNull::class, $violations->get(0)->getConstraint());
}

public function testAllConstraintValidateAllGroupsForNestedConstraints()
{
$this->metadata->addPropertyConstraint('data', new All(['constraints' => [
Expand Down
4 changes: 4 additions & 0 deletions Validator/RecursiveContextualValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,10 @@ private function validateGenericNode($value, $object, ?string $cacheKey, ?Metada

if ($value instanceof LazyProperty) {
$value = $value->getPropertyValue();

if (null === $value) {
return;
}
}

if (\is_array($value)) {
Expand Down

0 comments on commit f2b1e1d

Please sign in to comment.