minor #32128 [Validator] Add ExpressionValidator typehint & remove deprecation (ogizanagi)

This PR was merged into the 5.0-dev branch.

Discussion
----------

[Validator] Add ExpressionValidator typehint & remove deprecation

| Q             | A
| ------------- | ---
| Branch?       | master <!-- see below -->
| Bug fix?      | no
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no  <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #32041   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

Commits
-------

e4c4d2dce8 [Validator] Add ExpressionValidator typehint & remove deprecation
This commit is contained in:
Fabien Potencier 2019-06-22 10:26:14 +02:00
commit 2f9e69e117
3 changed files with 2 additions and 50 deletions

View File

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

View File

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

View File

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