File tree 2 files changed +26
-10
lines changed
src/Symfony/Component/Validator
2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change @@ -37,18 +37,10 @@ class ExpressionValidator extends ConstraintValidator
37
37
*/
38
38
private $ expressionLanguage ;
39
39
40
- /**
41
- * @param PropertyAccessorInterface|null $propertyAccessor Optional as of Symfony 2.5
42
- *
43
- * @throws UnexpectedTypeException If the property accessor is invalid
44
- */
45
- public function __construct ($ propertyAccessor = null )
40
+ public function __construct (PropertyAccessorInterface $ propertyAccessor = null , ExpressionLanguage $ expressionLanguage = null )
46
41
{
47
- if (null !== $ propertyAccessor && !$ propertyAccessor instanceof PropertyAccessorInterface) {
48
- throw new UnexpectedTypeException ($ propertyAccessor , 'null or \Symfony\Component\PropertyAccess\PropertyAccessorInterface ' );
49
- }
50
-
51
42
$ this ->propertyAccessor = $ propertyAccessor ;
43
+ $ this ->expressionLanguage = $ expressionLanguage ;
52
44
}
53
45
54
46
/**
Original file line number Diff line number Diff line change @@ -217,4 +217,28 @@ public function testFailingExpressionAtPropertyLevelWithoutRoot()
217
217
->setCode (Expression::EXPRESSION_FAILED_ERROR )
218
218
->assertRaised ();
219
219
}
220
+
221
+ public function testExpressionLanguageUsage ()
222
+ {
223
+ $ constraint = new Expression (array (
224
+ 'expression ' => 'false ' ,
225
+ ));
226
+
227
+ $ expressionLanguage = $ this ->getMock ('Symfony\Component\ExpressionLanguage\ExpressionLanguage ' );
228
+
229
+ $ used = false ;
230
+
231
+ $ expressionLanguage ->method ('evaluate ' )
232
+ ->will ($ this ->returnCallback (function () use (&$ used ) {
233
+ $ used = true ;
234
+
235
+ return true ;
236
+ }));
237
+
238
+ $ validator = new ExpressionValidator (null , $ expressionLanguage );
239
+ $ validator ->initialize ($ this ->createContext ());
240
+ $ validator ->validate (null , $ constraint );
241
+
242
+ $ this ->assertTrue ($ used , 'Failed asserting that custom ExpressionLanguage instance is used. ' );
243
+ }
220
244
}
You can’t perform that action at this time.
0 commit comments