Skip to content

Commit

Permalink
bug #33831 [Validator] Fix wrong expression language value (yceruto)
Browse files Browse the repository at this point in the history
This PR was merged into the 4.4 branch.

Discussion
----------

[Validator] Fix wrong expression language value

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

https://github.com/symfony/symfony/blob/766162c4c790cc0b91185963b9c36b842bf2eb49/src/Symfony/Component/Validator/Constraints/ExpressionValidator.php#L28

```php
(new ExpressionValidator($propertyAccessor))->validate($object, $constraint);
```
Based on the previous method signature (4.3 above), that code would result in an exception in 4.4:
```
Call to undefined method Symfony\Component\PropertyAccess\PropertyAccessor::evaluate()
```
Spotted by @fancyweb in #33829 (comment)

Fixed here and updated test case to avoid regression.

Commits
-------

4288f1c Fix wrong expression language value
  • Loading branch information
fabpot committed Oct 3, 2019
2 parents 2ccecbe + 4288f1c commit 496346c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 496346c

Please sign in to comment.