Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / validator / Tests / Constraints / ExpressionValidatorTest.php
index 420fb705762f0c845615de4c0b2e8e808e0ceacc..07f17d648aa39ef0c4df15d47977ee3017573a19 100644 (file)
 
 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');