@@ -40,14 +40,23 @@ public function testExpectArrayIfMultipleIsTrue()
40
40
$ constraint = new Choice (array (
41
41
'choices ' => array ('foo ' , 'bar ' ),
42
42
'multiple ' => true ,
43
+ 'strict ' => true ,
43
44
));
44
45
45
46
$ this ->validator ->validate ('asdf ' , $ constraint );
46
47
}
47
48
48
49
public function testNullIsValid ()
49
50
{
50
- $ this ->validator ->validate (null , new Choice (array ('choices ' => array ('foo ' , 'bar ' ))));
51
+ $ this ->validator ->validate (
52
+ null ,
53
+ new Choice (
54
+ array (
55
+ 'choices ' => array ('foo ' , 'bar ' ),
56
+ 'strict ' => true ,
57
+ )
58
+ )
59
+ );
51
60
52
61
$ this ->assertNoViolation ();
53
62
}
@@ -57,20 +66,20 @@ public function testNullIsValid()
57
66
*/
58
67
public function testChoicesOrCallbackExpected ()
59
68
{
60
- $ this ->validator ->validate ('foobar ' , new Choice ());
69
+ $ this ->validator ->validate ('foobar ' , new Choice (array ( ' strict ' => true ) ));
61
70
}
62
71
63
72
/**
64
73
* @expectedException \Symfony\Component\Validator\Exception\ConstraintDefinitionException
65
74
*/
66
75
public function testValidCallbackExpected ()
67
76
{
68
- $ this ->validator ->validate ('foobar ' , new Choice (array ('callback ' => 'abcd ' )));
77
+ $ this ->validator ->validate ('foobar ' , new Choice (array ('callback ' => 'abcd ' , ' strict ' => true )));
69
78
}
70
79
71
80
public function testValidChoiceArray ()
72
81
{
73
- $ constraint = new Choice (array ('choices ' => array ('foo ' , 'bar ' )));
82
+ $ constraint = new Choice (array ('choices ' => array ('foo ' , 'bar ' ), ' strict ' => true ));
74
83
75
84
$ this ->validator ->validate ('bar ' , $ constraint );
76
85
@@ -79,7 +88,7 @@ public function testValidChoiceArray()
79
88
80
89
public function testValidChoiceCallbackFunction ()
81
90
{
82
- $ constraint = new Choice (array ('callback ' => __NAMESPACE__ .'\choice_callback ' ));
91
+ $ constraint = new Choice (array ('callback ' => __NAMESPACE__ .'\choice_callback ' , ' strict ' => true ));
83
92
84
93
$ this ->validator ->validate ('bar ' , $ constraint );
85
94
@@ -88,9 +97,14 @@ public function testValidChoiceCallbackFunction()
88
97
89
98
public function testValidChoiceCallbackClosure ()
90
99
{
91
- $ constraint = new Choice (array ('callback ' => function () {
92
- return array ('foo ' , 'bar ' );
93
- }));
100
+ $ constraint = new Choice (
101
+ array (
102
+ 'strict ' => true ,
103
+ 'callback ' => function () {
104
+ return array ('foo ' , 'bar ' );
105
+ },
106
+ )
107
+ );
94
108
95
109
$ this ->validator ->validate ('bar ' , $ constraint );
96
110
@@ -99,7 +113,7 @@ public function testValidChoiceCallbackClosure()
99
113
100
114
public function testValidChoiceCallbackStaticMethod ()
101
115
{
102
- $ constraint = new Choice (array ('callback ' => array (__CLASS__ , 'staticCallback ' )));
116
+ $ constraint = new Choice (array ('callback ' => array (__CLASS__ , 'staticCallback ' ), ' strict ' => true ));
103
117
104
118
$ this ->validator ->validate ('bar ' , $ constraint );
105
119
@@ -111,7 +125,7 @@ public function testValidChoiceCallbackContextMethod()
111
125
// search $this for "staticCallback"
112
126
$ this ->setObject ($ this );
113
127
114
- $ constraint = new Choice (array ('callback ' => 'staticCallback ' ));
128
+ $ constraint = new Choice (array ('callback ' => 'staticCallback ' , ' strict ' => true ));
115
129
116
130
$ this ->validator ->validate ('bar ' , $ constraint );
117
131
@@ -123,6 +137,7 @@ public function testMultipleChoices()
123
137
$ constraint = new Choice (array (
124
138
'choices ' => array ('foo ' , 'bar ' , 'baz ' ),
125
139
'multiple ' => true ,
140
+ 'strict ' => true ,
126
141
));
127
142
128
143
$ this ->validator ->validate (array ('baz ' , 'bar ' ), $ constraint );
@@ -135,6 +150,7 @@ public function testInvalidChoice()
135
150
$ constraint = new Choice (array (
136
151
'choices ' => array ('foo ' , 'bar ' ),
137
152
'message ' => 'myMessage ' ,
153
+ 'strict ' => true ,
138
154
));
139
155
140
156
$ this ->validator ->validate ('baz ' , $ constraint );
@@ -152,6 +168,7 @@ public function testInvalidChoiceEmptyChoices()
152
168
// the DB or the model
153
169
'choices ' => array (),
154
170
'message ' => 'myMessage ' ,
171
+ 'strict ' => true ,
155
172
));
156
173
157
174
$ this ->validator ->validate ('baz ' , $ constraint );
@@ -168,6 +185,7 @@ public function testInvalidChoiceMultiple()
168
185
'choices ' => array ('foo ' , 'bar ' ),
169
186
'multipleMessage ' => 'myMessage ' ,
170
187
'multiple ' => true ,
188
+ 'strict ' => true ,
171
189
));
172
190
173
191
$ this ->validator ->validate (array ('foo ' , 'baz ' ), $ constraint );
@@ -186,6 +204,7 @@ public function testTooFewChoices()
186
204
'multiple ' => true ,
187
205
'min ' => 2 ,
188
206
'minMessage ' => 'myMessage ' ,
207
+ 'strict ' => true ,
189
208
));
190
209
191
210
$ value = array ('foo ' );
@@ -209,6 +228,7 @@ public function testTooManyChoices()
209
228
'multiple ' => true ,
210
229
'max ' => 2 ,
211
230
'maxMessage ' => 'myMessage ' ,
231
+ 'strict ' => true ,
212
232
));
213
233
214
234
$ value = array ('foo ' , 'bar ' , 'moo ' );
@@ -225,6 +245,9 @@ public function testTooManyChoices()
225
245
->assertRaised ();
226
246
}
227
247
248
+ /**
249
+ * @group legacy
250
+ */
228
251
public function testNonStrict ()
229
252
{
230
253
$ constraint = new Choice (array (
@@ -266,6 +289,9 @@ public function testStrictDisallowsDifferentType()
266
289
->assertRaised ();
267
290
}
268
291
292
+ /**
293
+ * @group legacy
294
+ */
269
295
public function testNonStrictWithMultipleChoices ()
270
296
{
271
297
$ constraint = new Choice (array (
0 commit comments