From 4288f1c9f93c3d18442213e9b998738c82950876 Mon Sep 17 00:00:00 2001 From: Yonel Ceruto Date: Thu, 3 Oct 2019 08:54:02 -0400 Subject: [PATCH] Fix wrong expression language value --- .../Validator/Constraints/ExpressionValidator.php | 2 ++ .../Tests/Constraints/ExpressionValidatorTest.php | 9 ++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index 58ce1606a9..3d061554d5 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -37,6 +37,8 @@ class ExpressionValidator extends ConstraintValidator } } elseif (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) { @trigger_error(sprintf('The "%s" first argument must be an instance of "%s" or null since 4.4. "%s" given', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)), E_USER_DEPRECATED); + + $expressionLanguage = null; } $this->expressionLanguage = $expressionLanguage; diff --git a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php index e1507fa8e9..c5b2ebee07 100644 --- a/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/src/Symfony/Component/Validator/Tests/Constraints/ExpressionValidatorTest.php @@ -12,6 +12,7 @@ namespace Symfony\Component\Validator\Tests\Constraints; use Symfony\Component\ExpressionLanguage\ExpressionLanguage; +use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\Validator\Constraints\Expression; use Symfony\Component\Validator\Constraints\ExpressionValidator; use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; @@ -302,11 +303,13 @@ class ExpressionValidatorTest extends ConstraintValidatorTestCase /** * @group legacy - * @expectedDeprecation The "Symfony\Component\Validator\Constraints\ExpressionValidator::__construct" first argument must be an instance of "Symfony\Component\ExpressionLanguage\ExpressionLanguage" or null since 4.4. "string" given + * @expectedDeprecation The "Symfony\Component\Validator\Constraints\ExpressionValidator::__construct" first argument must be an instance of "Symfony\Component\ExpressionLanguage\ExpressionLanguage" or null since 4.4. "Symfony\Component\PropertyAccess\PropertyAccessor" given */ - public function testConstructorInvalidType() + public function testDeprecatedArgumentType() { - new ExpressionValidator('foo'); + $validator = new ExpressionValidator(PropertyAccess::createPropertyAccessor()); + $validator->initialize($this->createContext()); + $validator->validate(null, new Expression(['expression' => 'false'])); } public function testPassingCustomValues()