17
17
18
18
function choice_callback ()
19
19
{
20
- return array ( 'foo ' , 'bar ' ) ;
20
+ return [ 'foo ' , 'bar ' ] ;
21
21
}
22
22
23
23
class ChoiceValidatorTest extends ConstraintValidatorTestCase
@@ -29,23 +29,23 @@ protected function createValidator()
29
29
30
30
public static function staticCallback ()
31
31
{
32
- return array ( 'foo ' , 'bar ' ) ;
32
+ return [ 'foo ' , 'bar ' ] ;
33
33
}
34
34
35
35
public function objectMethodCallback ()
36
36
{
37
- return array ( 'foo ' , 'bar ' ) ;
37
+ return [ 'foo ' , 'bar ' ] ;
38
38
}
39
39
40
40
/**
41
41
* @expectedException \Symfony\Component\Validator\Exception\UnexpectedTypeException
42
42
*/
43
43
public function testExpectArrayIfMultipleIsTrue ()
44
44
{
45
- $ constraint = new Choice (array (
46
- 'choices ' => array ( 'foo ' , 'bar ' ) ,
45
+ $ constraint = new Choice ([
46
+ 'choices ' => [ 'foo ' , 'bar ' ] ,
47
47
'multiple ' => true ,
48
- ) );
48
+ ] );
49
49
50
50
$ this ->validator ->validate ('asdf ' , $ constraint );
51
51
}
@@ -55,9 +55,9 @@ public function testNullIsValid()
55
55
$ this ->validator ->validate (
56
56
null ,
57
57
new Choice (
58
- array (
59
- 'choices ' => array ( 'foo ' , 'bar ' ) ,
60
- )
58
+ [
59
+ 'choices ' => [ 'foo ' , 'bar ' ] ,
60
+ ]
61
61
)
62
62
);
63
63
@@ -77,12 +77,12 @@ public function testChoicesOrCallbackExpected()
77
77
*/
78
78
public function testValidCallbackExpected ()
79
79
{
80
- $ this ->validator ->validate ('foobar ' , new Choice (array ( 'callback ' => 'abcd ' ) ));
80
+ $ this ->validator ->validate ('foobar ' , new Choice ([ 'callback ' => 'abcd ' ] ));
81
81
}
82
82
83
83
public function testValidChoiceArray ()
84
84
{
85
- $ constraint = new Choice (array ( 'choices ' => array ( 'foo ' , 'bar ' )) );
85
+ $ constraint = new Choice ([ 'choices ' => [ 'foo ' , 'bar ' ]] );
86
86
87
87
$ this ->validator ->validate ('bar ' , $ constraint );
88
88
@@ -91,7 +91,7 @@ public function testValidChoiceArray()
91
91
92
92
public function testValidChoiceCallbackFunction ()
93
93
{
94
- $ constraint = new Choice (array ( 'callback ' => __NAMESPACE__ .'\choice_callback ' ) );
94
+ $ constraint = new Choice ([ 'callback ' => __NAMESPACE__ .'\choice_callback ' ] );
95
95
96
96
$ this ->validator ->validate ('bar ' , $ constraint );
97
97
@@ -101,11 +101,11 @@ public function testValidChoiceCallbackFunction()
101
101
public function testValidChoiceCallbackClosure ()
102
102
{
103
103
$ constraint = new Choice (
104
- array (
104
+ [
105
105
'callback ' => function () {
106
- return array ( 'foo ' , 'bar ' ) ;
106
+ return [ 'foo ' , 'bar ' ] ;
107
107
},
108
- )
108
+ ]
109
109
);
110
110
111
111
$ this ->validator ->validate ('bar ' , $ constraint );
@@ -115,7 +115,7 @@ public function testValidChoiceCallbackClosure()
115
115
116
116
public function testValidChoiceCallbackStaticMethod ()
117
117
{
118
- $ constraint = new Choice (array ( 'callback ' => array ( __CLASS__ , 'staticCallback ' )) );
118
+ $ constraint = new Choice ([ 'callback ' => [ __CLASS__ , 'staticCallback ' ]] );
119
119
120
120
$ this ->validator ->validate ('bar ' , $ constraint );
121
121
@@ -127,7 +127,7 @@ public function testValidChoiceCallbackContextMethod()
127
127
// search $this for "staticCallback"
128
128
$ this ->setObject ($ this );
129
129
130
- $ constraint = new Choice (array ( 'callback ' => 'staticCallback ' ) );
130
+ $ constraint = new Choice ([ 'callback ' => 'staticCallback ' ] );
131
131
132
132
$ this ->validator ->validate ('bar ' , $ constraint );
133
133
@@ -139,7 +139,7 @@ public function testValidChoiceCallbackContextObjectMethod()
139
139
// search $this for "objectMethodCallback"
140
140
$ this ->setObject ($ this );
141
141
142
- $ constraint = new Choice (array ( 'callback ' => 'objectMethodCallback ' ) );
142
+ $ constraint = new Choice ([ 'callback ' => 'objectMethodCallback ' ] );
143
143
144
144
$ this ->validator ->validate ('bar ' , $ constraint );
145
145
@@ -148,22 +148,22 @@ public function testValidChoiceCallbackContextObjectMethod()
148
148
149
149
public function testMultipleChoices ()
150
150
{
151
- $ constraint = new Choice (array (
152
- 'choices ' => array ( 'foo ' , 'bar ' , 'baz ' ) ,
151
+ $ constraint = new Choice ([
152
+ 'choices ' => [ 'foo ' , 'bar ' , 'baz ' ] ,
153
153
'multiple ' => true ,
154
- ) );
154
+ ] );
155
155
156
- $ this ->validator ->validate (array ( 'baz ' , 'bar ' ) , $ constraint );
156
+ $ this ->validator ->validate ([ 'baz ' , 'bar ' ] , $ constraint );
157
157
158
158
$ this ->assertNoViolation ();
159
159
}
160
160
161
161
public function testInvalidChoice ()
162
162
{
163
- $ constraint = new Choice (array (
164
- 'choices ' => array ( 'foo ' , 'bar ' ) ,
163
+ $ constraint = new Choice ([
164
+ 'choices ' => [ 'foo ' , 'bar ' ] ,
165
165
'message ' => 'myMessage ' ,
166
- ) );
166
+ ] );
167
167
168
168
$ this ->validator ->validate ('baz ' , $ constraint );
169
169
@@ -175,12 +175,12 @@ public function testInvalidChoice()
175
175
176
176
public function testInvalidChoiceEmptyChoices ()
177
177
{
178
- $ constraint = new Choice (array (
178
+ $ constraint = new Choice ([
179
179
// May happen when the choices are provided dynamically, e.g. from
180
180
// the DB or the model
181
- 'choices ' => array () ,
181
+ 'choices ' => [] ,
182
182
'message ' => 'myMessage ' ,
183
- ) );
183
+ ] );
184
184
185
185
$ this ->validator ->validate ('baz ' , $ constraint );
186
186
@@ -192,13 +192,13 @@ public function testInvalidChoiceEmptyChoices()
192
192
193
193
public function testInvalidChoiceMultiple ()
194
194
{
195
- $ constraint = new Choice (array (
196
- 'choices ' => array ( 'foo ' , 'bar ' ) ,
195
+ $ constraint = new Choice ([
196
+ 'choices ' => [ 'foo ' , 'bar ' ] ,
197
197
'multipleMessage ' => 'myMessage ' ,
198
198
'multiple ' => true ,
199
- ) );
199
+ ] );
200
200
201
- $ this ->validator ->validate (array ( 'foo ' , 'baz ' ) , $ constraint );
201
+ $ this ->validator ->validate ([ 'foo ' , 'baz ' ] , $ constraint );
202
202
203
203
$ this ->buildViolation ('myMessage ' )
204
204
->setParameter ('{{ value }} ' , '"baz" ' )
@@ -209,14 +209,14 @@ public function testInvalidChoiceMultiple()
209
209
210
210
public function testTooFewChoices ()
211
211
{
212
- $ constraint = new Choice (array (
213
- 'choices ' => array ( 'foo ' , 'bar ' , 'moo ' , 'maa ' ) ,
212
+ $ constraint = new Choice ([
213
+ 'choices ' => [ 'foo ' , 'bar ' , 'moo ' , 'maa ' ] ,
214
214
'multiple ' => true ,
215
215
'min ' => 2 ,
216
216
'minMessage ' => 'myMessage ' ,
217
- ) );
217
+ ] );
218
218
219
- $ value = array ( 'foo ' ) ;
219
+ $ value = [ 'foo ' ] ;
220
220
221
221
$ this ->setValue ($ value );
222
222
@@ -232,14 +232,14 @@ public function testTooFewChoices()
232
232
233
233
public function testTooManyChoices ()
234
234
{
235
- $ constraint = new Choice (array (
236
- 'choices ' => array ( 'foo ' , 'bar ' , 'moo ' , 'maa ' ) ,
235
+ $ constraint = new Choice ([
236
+ 'choices ' => [ 'foo ' , 'bar ' , 'moo ' , 'maa ' ] ,
237
237
'multiple ' => true ,
238
238
'max ' => 2 ,
239
239
'maxMessage ' => 'myMessage ' ,
240
- ) );
240
+ ] );
241
241
242
- $ value = array ( 'foo ' , 'bar ' , 'moo ' ) ;
242
+ $ value = [ 'foo ' , 'bar ' , 'moo ' ] ;
243
243
244
244
$ this ->setValue ($ value );
245
245
@@ -255,9 +255,9 @@ public function testTooManyChoices()
255
255
256
256
public function testStrictAllowsExactValue ()
257
257
{
258
- $ constraint = new Choice (array (
259
- 'choices ' => array ( 1 , 2 ) ,
260
- ) );
258
+ $ constraint = new Choice ([
259
+ 'choices ' => [ 1 , 2 ] ,
260
+ ] );
261
261
262
262
$ this ->validator ->validate (2 , $ constraint );
263
263
@@ -266,10 +266,10 @@ public function testStrictAllowsExactValue()
266
266
267
267
public function testStrictDisallowsDifferentType ()
268
268
{
269
- $ constraint = new Choice (array (
270
- 'choices ' => array ( 1 , 2 ) ,
269
+ $ constraint = new Choice ([
270
+ 'choices ' => [ 1 , 2 ] ,
271
271
'message ' => 'myMessage ' ,
272
- ) );
272
+ ] );
273
273
274
274
$ this ->validator ->validate ('2 ' , $ constraint );
275
275
@@ -281,13 +281,13 @@ public function testStrictDisallowsDifferentType()
281
281
282
282
public function testStrictWithMultipleChoices ()
283
283
{
284
- $ constraint = new Choice (array (
285
- 'choices ' => array ( 1 , 2 , 3 ) ,
284
+ $ constraint = new Choice ([
285
+ 'choices ' => [ 1 , 2 , 3 ] ,
286
286
'multiple ' => true ,
287
287
'multipleMessage ' => 'myMessage ' ,
288
- ) );
288
+ ] );
289
289
290
- $ this ->validator ->validate (array ( 2 , '3 ' ) , $ constraint );
290
+ $ this ->validator ->validate ([ 2 , '3 ' ] , $ constraint );
291
291
292
292
$ this ->buildViolation ('myMessage ' )
293
293
->setParameter ('{{ value }} ' , '"3" ' )
0 commit comments