X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=vendor%2Fsymfony%2Fvalidator%2FTests%2FConstraints%2FExpressionValidatorTest.php;h=07f17d648aa39ef0c4df15d47977ee3017573a19;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=420fb705762f0c845615de4c0b2e8e808e0ceacc;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/symfony/validator/Tests/Constraints/ExpressionValidatorTest.php b/vendor/symfony/validator/Tests/Constraints/ExpressionValidatorTest.php index 420fb7057..07f17d648 100644 --- a/vendor/symfony/validator/Tests/Constraints/ExpressionValidatorTest.php +++ b/vendor/symfony/validator/Tests/Constraints/ExpressionValidatorTest.php @@ -11,22 +11,17 @@ namespace Symfony\Component\Validator\Tests\Constraints; -use Symfony\Component\PropertyAccess\PropertyAccess; use Symfony\Component\Validator\Constraints\Expression; use Symfony\Component\Validator\Constraints\ExpressionValidator; +use Symfony\Component\Validator\Test\ConstraintValidatorTestCase; use Symfony\Component\Validator\Tests\Fixtures\Entity; -use Symfony\Component\Validator\Validation; +use Symfony\Component\Validator\Tests\Fixtures\ToString; -class ExpressionValidatorTest extends AbstractConstraintValidatorTest +class ExpressionValidatorTest extends ConstraintValidatorTestCase { - protected function getApiVersion() - { - return Validation::API_VERSION_2_5; - } - protected function createValidator() { - return new ExpressionValidator(PropertyAccess::createPropertyAccessor()); + return new ExpressionValidator(); } public function testExpressionIsEvaluatedWithNullValue() @@ -93,6 +88,40 @@ class ExpressionValidatorTest extends AbstractConstraintValidatorTest ->assertRaised(); } + public function testSucceedingExpressionAtObjectLevelWithToString() + { + $constraint = new Expression('this.data == 1'); + + $object = new ToString(); + $object->data = '1'; + + $this->setObject($object); + + $this->validator->validate($object, $constraint); + + $this->assertNoViolation(); + } + + public function testFailingExpressionAtObjectLevelWithToString() + { + $constraint = new Expression(array( + 'expression' => 'this.data == 1', + 'message' => 'myMessage', + )); + + $object = new ToString(); + $object->data = '2'; + + $this->setObject($object); + + $this->validator->validate($object, $constraint); + + $this->buildViolation('myMessage') + ->setParameter('{{ value }}', 'toString') + ->setCode(Expression::EXPRESSION_FAILED_ERROR) + ->assertRaised(); + } + public function testSucceedingExpressionAtPropertyLevel() { $constraint = new Expression('value == this.data');