Fix wrong expression language value

This commit is contained in:
Yonel Ceruto 2019-10-03 08:54:02 -04:00
parent 11da6f6eea
commit 4288f1c9f9
2 changed files with 8 additions and 3 deletions

View File

@ -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;

View File

@ -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()