@@ -53,4 +53,59 @@ public function testToStringHandlesArrayRoots()
5353
5454 $ this ->assertSame ($ expected , (string ) $ violation );
5555 }
56+
57+ public function testToStringHandlesCodes ()
58+ {
59+ $ violation = new ConstraintViolation (
60+ '42 cannot be used here ' ,
61+ 'this is the message template ' ,
62+ array (),
63+ array ('some_value ' => 42 ),
64+ 'some_value ' ,
65+ null ,
66+ null ,
67+ 0
68+ );
69+
70+ $ expected = <<<'EOF'
71+ Array.some_value:
72+ 42 cannot be used here (code 0)
73+ EOF;
74+
75+ $ this ->assertSame ($ expected , (string ) $ violation );
76+ }
77+
78+ public function testToStringOmitsEmptyCodes ()
79+ {
80+ $ expected = <<<'EOF'
81+ Array.some_value:
82+ 42 cannot be used here
83+ EOF;
84+
85+ $ violation = new ConstraintViolation (
86+ '42 cannot be used here ' ,
87+ 'this is the message template ' ,
88+ array (),
89+ array ('some_value ' => 42 ),
90+ 'some_value ' ,
91+ null ,
92+ null ,
93+ null
94+ );
95+
96+ $ this ->assertSame ($ expected , (string ) $ violation );
97+
98+ $ violation = new ConstraintViolation (
99+ '42 cannot be used here ' ,
100+ 'this is the message template ' ,
101+ array (),
102+ array ('some_value ' => 42 ),
103+ 'some_value ' ,
104+ null ,
105+ null ,
106+ ''
107+ );
108+
109+ $ this ->assertSame ($ expected , (string ) $ violation );
110+ }
56111}
0 commit comments