@@ -194,4 +194,60 @@ public function testFailingExpressionAtNestedPropertyLevel()
194
194
195
195
$ this ->validator ->validate ('2 ' , $ constraint );
196
196
}
197
+
198
+ /**
199
+ * When validatePropertyValue() is called with a class name
200
+ * https://github.com/symfony/symfony/pull/11498
201
+ */
202
+ public function testSucceedingExpressionAtPropertyLevelWithoutRoot ()
203
+ {
204
+ $ constraint = new Expression ('value == "1" ' );
205
+
206
+ $ this ->context ->expects ($ this ->any ())
207
+ ->method ('getPropertyName ' )
208
+ ->will ($ this ->returnValue ('property ' ));
209
+
210
+ $ this ->context ->expects ($ this ->any ())
211
+ ->method ('getPropertyPath ' )
212
+ ->will ($ this ->returnValue ('' ));
213
+
214
+ $ this ->context ->expects ($ this ->any ())
215
+ ->method ('getRoot ' )
216
+ ->will ($ this ->returnValue ('1 ' ));
217
+
218
+ $ this ->context ->expects ($ this ->never ())
219
+ ->method ('addViolation ' );
220
+
221
+ $ this ->validator ->validate ('1 ' , $ constraint );
222
+ }
223
+
224
+ /**
225
+ * When validatePropertyValue() is called with a class name
226
+ * https://github.com/symfony/symfony/pull/11498
227
+ */
228
+ public function testFailingExpressionAtPropertyLevelWithoutRoot ()
229
+ {
230
+ $ constraint = new Expression (array (
231
+ 'expression ' => 'value == "1" ' ,
232
+ 'message ' => 'myMessage ' ,
233
+ ));
234
+
235
+ $ this ->context ->expects ($ this ->any ())
236
+ ->method ('getPropertyName ' )
237
+ ->will ($ this ->returnValue ('property ' ));
238
+
239
+ $ this ->context ->expects ($ this ->any ())
240
+ ->method ('getPropertyPath ' )
241
+ ->will ($ this ->returnValue ('' ));
242
+
243
+ $ this ->context ->expects ($ this ->any ())
244
+ ->method ('getRoot ' )
245
+ ->will ($ this ->returnValue ('2 ' ));
246
+
247
+ $ this ->context ->expects ($ this ->once ())
248
+ ->method ('addViolation ' )
249
+ ->with ('myMessage ' );
250
+
251
+ $ this ->validator ->validate ('2 ' , $ constraint );
252
+ }
197
253
}
0 commit comments