From 776daf28b4e5240a830ff0c724604a4968e51b24 Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Mon, 29 Jun 2020 12:48:16 +0200 Subject: [PATCH 1/3] fix validating lazy properties that evaluate to null --- .../Validator/Tests/Fixtures/EntityParent.php | 6 +++++ .../Validator/RecursiveValidatorTest.php | 27 +++++++++++++++++++ .../RecursiveContextualValidator.php | 4 +++ 3 files changed, 37 insertions(+) diff --git a/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php b/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php index 4674f8b35a..eb09e5a4b2 100644 --- a/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php +++ b/src/Symfony/Component/Validator/Tests/Fixtures/EntityParent.php @@ -18,6 +18,7 @@ class EntityParent implements EntityInterfaceA protected $firstName; private $internal; private $data = 'Data'; + private $child; /** * @NotNull @@ -28,4 +29,9 @@ class EntityParent implements EntityInterfaceA { return 'Data'; } + + public function getChild() + { + return $this->child; + } } diff --git a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php index 484236241c..c9e30b4587 100644 --- a/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Validator/RecursiveValidatorTest.php @@ -21,6 +21,7 @@ use Symfony\Component\Validator\Constraints\NotBlank; 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; @@ -28,6 +29,7 @@ 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; @@ -143,6 +145,31 @@ class RecursiveValidatorTest extends AbstractTest $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' => [ diff --git a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php index 24206bfc27..a51e66d290 100644 --- a/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php +++ b/src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php @@ -680,6 +680,10 @@ class RecursiveContextualValidator implements ContextualValidatorInterface if ($value instanceof LazyProperty) { $value = $value->getPropertyValue(); + + if (null === $value) { + return; + } } if (\is_array($value)) { From 5c5ea7500eea9c04b12f8d14adafb2f537b41e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Pineau?= Date: Tue, 30 Jun 2020 14:50:28 +0200 Subject: [PATCH 2/3] Removed comments and requirements relative to php <5.5 (not supported anymore) --- src/Symfony/Component/Console/Command/Command.php | 2 -- .../DateTimeToHtml5LocalDateTimeTransformerTest.php | 1 - src/Symfony/Component/HttpFoundation/Tests/CookieTest.php | 3 --- 3 files changed, 6 deletions(-) diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 311fdb6a14..e39cc3ba41 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -437,8 +437,6 @@ class Command * This feature should be used only when creating a long process command, * like a daemon. * - * PHP 5.5+ or the proctitle PECL library is required - * * @param string $title The process title * * @return $this diff --git a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformerTest.php b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformerTest.php index 5fd6c69f5e..aef3e68829 100644 --- a/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformerTest.php +++ b/src/Symfony/Component/Form/Tests/Extension/Core/DataTransformer/DateTimeToHtml5LocalDateTimeTransformerTest.php @@ -63,7 +63,6 @@ class DateTimeToHtml5LocalDateTimeTransformerTest extends TestCase /** * @dataProvider transformProvider - * @requires PHP 5.5 */ public function testTransformDateTimeImmutable($fromTz, $toTz, $from, $to) { diff --git a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php index 169f917875..637cff0d09 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/CookieTest.php @@ -115,9 +115,6 @@ class CookieTest extends TestCase $this->assertEquals($expire->format('U'), $cookie->getExpiresTime(), '->getExpiresTime() returns the expire date'); } - /** - * @requires PHP 5.5 - */ public function testConstructorWithDateTimeImmutable() { $expire = new \DateTimeImmutable(); From aeb46373410d168b995aeab34f725092616a67f0 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 30 Jun 2020 19:26:29 +0200 Subject: [PATCH 3/3] [ErrorHandler] fix throwing from __toString() --- src/Symfony/Component/Debug/ErrorHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/Debug/ErrorHandler.php b/src/Symfony/Component/Debug/ErrorHandler.php index 40a4b1758c..1e60b5ca98 100644 --- a/src/Symfony/Component/Debug/ErrorHandler.php +++ b/src/Symfony/Component/Debug/ErrorHandler.php @@ -401,7 +401,7 @@ class ErrorHandler $scope = $this->scopedErrors & $type; if (4 < $numArgs = \func_num_args()) { - $context = $scope ? (func_get_arg(4) ?: []) : []; + $context = func_get_arg(4) ?: []; $backtrace = 5 < $numArgs ? func_get_arg(5) : null; // defined on HHVM } else { $context = [];