diff --git a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php index 58ce1606a9c7..3d061554d5a7 100644 --- a/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php +++ b/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php @@ -37,6 +37,8 @@ public function __construct(/*ExpressionLanguage */$expressionLanguage = null) } } 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 e1507fa8e93f..c5b2ebee074c 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 @@ public function testLegacyExpressionLanguageUsage() /** * @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()