File tree Expand file tree Collapse file tree 3 files changed +67
-5
lines changed Expand file tree Collapse file tree 3 files changed +67
-5
lines changed Original file line number Diff line number Diff line change @@ -108,4 +108,66 @@ public function testToStringOmitsEmptyCodes()
108
108
109
109
$ this ->assertSame ($ expected , (string ) $ violation );
110
110
}
111
+
112
+ public function testMessageCanBeStringableObject ()
113
+ {
114
+ $ message = new ToString ();
115
+ $ violation = new ConstraintViolation (
116
+ $ message ,
117
+ (string ) $ message ,
118
+ [],
119
+ 'Root ' ,
120
+ 'property.path ' ,
121
+ null
122
+ );
123
+
124
+ $ expected = <<<'EOF'
125
+ Root.property.path:
126
+ toString
127
+ EOF;
128
+ $ this ->assertSame ($ expected , (string ) $ violation );
129
+ $ this ->assertSame ((string ) $ message , $ violation ->getMessage ());
130
+ }
131
+
132
+ public function testMessageCannotBeArray ()
133
+ {
134
+ $ this ->expectException (\TypeError::class);
135
+ $ violation = new ConstraintViolation (
136
+ ['cannot be an array ' ],
137
+ '' ,
138
+ [],
139
+ 'Root ' ,
140
+ 'property.path ' ,
141
+ null
142
+ );
143
+ }
144
+
145
+ public function testMessageObjectMustBeStringable ()
146
+ {
147
+ $ this ->expectException (\TypeError::class);
148
+ $ violation = new ConstraintViolation (
149
+ new CustomArrayObject (),
150
+ '' ,
151
+ [],
152
+ 'Root ' ,
153
+ 'property.path ' ,
154
+ null
155
+ );
156
+ }
157
+
158
+ public function testNonStringCode ()
159
+ {
160
+ $ violation = new ConstraintViolation (
161
+ '42 cannot be used here ' ,
162
+ 'this is the message template ' ,
163
+ [],
164
+ ['some_value ' => 42 ],
165
+ 'some_value ' ,
166
+ null ,
167
+ null ,
168
+ 42
169
+ );
170
+
171
+ self ::assertSame (42 , $ violation ->getCode ());
172
+ }
111
173
}
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ public function __construct(array $array = null)
24
24
$ this ->array = $ array ?: [];
25
25
}
26
26
27
- public function offsetExists ($ offset )
27
+ public function offsetExists ($ offset ): bool
28
28
{
29
29
return \array_key_exists ($ offset , $ this ->array );
30
30
}
@@ -48,12 +48,12 @@ public function offsetUnset($offset)
48
48
unset($ this ->array [$ offset ]);
49
49
}
50
50
51
- public function getIterator ()
51
+ public function getIterator (): \ Traversable
52
52
{
53
53
return new \ArrayIterator ($ this ->array );
54
54
}
55
55
56
- public function count ()
56
+ public function count (): int
57
57
{
58
58
return \count ($ this ->array );
59
59
}
@@ -63,7 +63,7 @@ public function __serialize(): array
63
63
return $ this ->array ;
64
64
}
65
65
66
- public function serialize ()
66
+ public function serialize (): string
67
67
{
68
68
return serialize ($ this ->__serialize ());
69
69
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ class ToString
15
15
{
16
16
public $ data ;
17
17
18
- public function __toString ()
18
+ public function __toString (): string
19
19
{
20
20
return 'toString ' ;
21
21
}
You can’t perform that action at this time.
0 commit comments