File tree 2 files changed +15
-6
lines changed
src/Symfony/Component/Validator 2 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ class NullValidator extends ConstraintValidator
27
27
public function validate ($ value , Constraint $ constraint )
28
28
{
29
29
if (null !== $ value ) {
30
+ if (is_object ($ value )) {
31
+ $ value = get_class ($ value );
32
+ } elseif (is_array ($ value )) {
33
+ $ value = 'Array ' ;
34
+ }
35
+
30
36
$ this ->context ->addViolation ($ constraint ->message , array ('{{ value }} ' => $ value ));
31
37
}
32
38
}
Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ public function testNullIsValid()
43
43
/**
44
44
* @dataProvider getInvalidValues
45
45
*/
46
- public function testInvalidValues ($ value )
46
+ public function testInvalidValues ($ value, $ readableValue )
47
47
{
48
48
$ constraint = new Null (array (
49
49
'message ' => 'myMessage '
@@ -52,7 +52,7 @@ public function testInvalidValues($value)
52
52
$ this ->context ->expects ($ this ->once ())
53
53
->method ('addViolation ' )
54
54
->with ('myMessage ' , array (
55
- '{{ value }} ' => $ value ,
55
+ '{{ value }} ' => $ readableValue ,
56
56
));
57
57
58
58
$ this ->validator ->validate ($ value , $ constraint );
@@ -61,10 +61,13 @@ public function testInvalidValues($value)
61
61
public function getInvalidValues ()
62
62
{
63
63
return array (
64
- array (0 ),
65
- array (false ),
66
- array (true ),
67
- array ('' ),
64
+ array (0 , 0 ),
65
+ array (false , false ),
66
+ array (true , true ),
67
+ array ('' , '' ),
68
+ array ('foo bar ' , 'foo bar ' ),
69
+ array (new \DateTime (), 'DateTime ' ),
70
+ array (array (), 'Array ' ),
68
71
);
69
72
}
70
73
}
You can’t perform that action at this time.
0 commit comments