[Validator] Add ExpressionValidator typehint & remove deprecation
This commit is contained in:
parent
16ff6ee3b8
commit
e4c4d2dce8
@ -4,6 +4,7 @@ CHANGELOG
|
||||
5.0.0
|
||||
-----
|
||||
|
||||
* an `ExpressionLanguage` instance or null must be passed as the first argument of `ExpressionValidator::__construct()`
|
||||
* removed the `checkDNS` and `dnsMessage` options of the `Url` constraint
|
||||
* removed the `checkMX`, `checkHost` and `strict` options of the `Email` constraint
|
||||
* removed support for validating instances of `\DateTimeInterface` in `DateTimeValidator`, `DateValidator` and `TimeValidator`
|
||||
|
@ -24,20 +24,8 @@ class ExpressionValidator extends ConstraintValidator
|
||||
{
|
||||
private $expressionLanguage;
|
||||
|
||||
public function __construct(/*ExpressionLanguage */$expressionLanguage = null)
|
||||
public function __construct(ExpressionLanguage $expressionLanguage = null)
|
||||
{
|
||||
if (\func_num_args() > 1) {
|
||||
@trigger_error(sprintf('The "%s" instance should be passed as "%s" first argument instead of second argument since 4.4.', ExpressionLanguage::class, __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
$expressionLanguage = func_get_arg(1);
|
||||
|
||||
if (null !== $expressionLanguage && !$expressionLanguage instanceof ExpressionLanguage) {
|
||||
throw new \TypeError(sprintf('Argument 2 passed to %s() must be an instance of %s or null, %s given. Since 4.4, passing it as the second argument is deprecated and will trigger a deprecation. Pass it as the first argument instead.', __METHOD__, ExpressionLanguage::class, \is_object($expressionLanguage) ? \get_class($expressionLanguage) : \gettype($expressionLanguage)));
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
|
||||
$this->expressionLanguage = $expressionLanguage;
|
||||
}
|
||||
|
||||
|
@ -272,43 +272,6 @@ class ExpressionValidatorTest extends ConstraintValidatorTestCase
|
||||
$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation The "Symfony\Component\ExpressionLanguage\ExpressionLanguage" instance should be passed as "Symfony\Component\Validator\Constraints\ExpressionValidator::__construct" first argument instead of second argument since 4.4.
|
||||
*/
|
||||
public function testLegacyExpressionLanguageUsage()
|
||||
{
|
||||
$constraint = new Expression([
|
||||
'expression' => 'false',
|
||||
]);
|
||||
|
||||
$expressionLanguage = $this->getMockBuilder('Symfony\Component\ExpressionLanguage\ExpressionLanguage')->getMock();
|
||||
|
||||
$used = false;
|
||||
|
||||
$expressionLanguage->method('evaluate')
|
||||
->willReturnCallback(function () use (&$used) {
|
||||
$used = true;
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$validator = new ExpressionValidator(null, $expressionLanguage);
|
||||
$validator->initialize($this->createContext());
|
||||
$validator->validate(null, $constraint);
|
||||
|
||||
$this->assertTrue($used, 'Failed asserting that custom ExpressionLanguage instance is used.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
public function testConstructorInvalidType()
|
||||
{
|
||||
new ExpressionValidator('foo');
|
||||
}
|
||||
|
||||
public function testPassingCustomValues()
|
||||
{
|
||||
$constraint = new Expression([
|
||||
|
Reference in New Issue
Block a user