Completed
Push — feature/EVO-5751-text-index-mo... ( 0ab3ac...8fecb1 )
by
unknown
62:16 queued 57:01
created

EmbedArrayTest::dataValid()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 115
Code Lines 81

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 115
rs 8.2857
cc 1
eloc 81
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * EmbedArrayTest class file
4
 */
5
6
namespace Graviton\CoreBundle\Tests\Controller;
7
8
use Graviton\TestBundle\Test\RestTestCase;
9
use Symfony\Component\HttpFoundation\Response;
10
11
/**
12
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
13
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
14
 * @link     http://swisscom.ch
15
 */
16
class EmbedArrayTest extends RestTestCase
17
{
18
    /**
19
     * @param object $data JSON data
20
     * @return void
21
     *
22
     * @dataProvider dataValid
23
     * @group newEmbed
24
     * @group newEmbedValid
25
     * @group newEmbedArray
26
     * @group newEmbedArrayValid
27
     */
28
    public function testValid($data)
29
    {
30
        $client = static::createRestClient();
31
        $client->post('/testcase/embed-array/', $data);
32
33
        $this->assertEquals(Response::HTTP_CREATED, $client->getResponse()->getStatusCode());
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function dataValid()
40
    {
41
        return [
42
            'all' => [
43
                (object) [
44
                    'value'         => 'value',
45
                    'defaultArray'  => [
46
                        (object) [
47
                            'value'             => 'defaultArray.value',
48
                            'subDefaultHash'    => (object) ['value' => 'defaultArray.subDefaultHash.value'],
49
                            'subOptionalHash'   => (object) ['value' => 'defaultArray.subOptionalHash.value'],
50
                            'subRequiredHash'   => (object) ['value' => 'defaultArray.subRequiredHash.value'],
51
                        ],
52
                    ],
53
                    'optionalArray' => [
54
                        (object) [
55
                            'value'             => 'defaultArray.value',
56
                            'subDefaultHash'    => (object) ['value' => 'optionalArray.subDefaultHash.value'],
57
                            'subOptionalHash'   => (object) ['value' => 'optionalArray.subOptionalHash.value'],
58
                            'subRequiredHash'   => (object) ['value' => 'optionalArray.subRequiredHash.value'],
59
                        ],
60
                    ],
61
                    'requiredArray' => [
62
                        (object) [
63
                            'value'             => 'defaultArray.value',
64
                            'subDefaultHash'    => (object) ['value' => 'requiredArray.subDefaultHash.value'],
65
                            'subOptionalHash'   => (object) ['value' => 'requiredArray.subOptionalHash.value'],
66
                            'subRequiredHash'   => (object) ['value' => 'requiredArray.subRequiredHash.value'],
67
                        ],
68
                    ],
69
                    'notEmptyArray' => [
70
                        (object) [
71
                            'value'             => 'notEmptyArray.value',
72
                            'subDefaultHash'    => (object) ['value' => 'notEmptyArray.subDefaultHash.value'],
73
                            'subOptionalHash'   => (object) ['value' => 'notEmptyArray.subOptionalHash.value'],
74
                            'subRequiredHash'   => (object) ['value' => 'notEmptyArray.subRequiredHash.value'],
75
                        ],
76
                    ],
77
                ],
78
            ],
79
            'all empty' => [
80
                (object) [
81
                    'value'         => 'value',
82
                    'defaultArray'  => [],
83
                    'optionalArray' => [],
84
                    'requiredArray' => [],
85
                    'notEmptyArray' => [
86
                        (object) [
87
                            'value'             => 'notEmptyArray.value',
88
                            'subDefaultHash'    => (object) ['value' => 'notEmptyArray.subDefaultHash.value'],
89
                            'subOptionalHash'   => (object) ['value' => 'notEmptyArray.subOptionalHash.value'],
90
                            'subRequiredHash'   => (object) ['value' => 'notEmptyArray.subRequiredHash.value'],
91
                        ],
92
                    ],
93
                ],
94
            ],
95
96
            'no optionalArray' => [
97
                (object) [
98
                    'value'         => 'value',
99
                    'defaultArray'  => [],
100
                    'requiredArray' => [],
101
                    'notEmptyArray' => [
102
                        (object) [
103
                            'value'             => 'notEmptyArray.value',
104
                            'subDefaultHash'    => (object) ['value' => 'notEmptyArray.subDefaultHash.value'],
105
                            'subOptionalHash'   => (object) ['value' => 'notEmptyArray.subOptionalHash.value'],
106
                            'subRequiredHash'   => (object) ['value' => 'notEmptyArray.subRequiredHash.value'],
107
                        ],
108
                    ],
109
                ],
110
            ],
111
            'no notEmptyArray' => [
112
                (object) [
113
                    'value'         => 'value',
114
                    'defaultArray'  => [],
115
                    'requiredArray' => [],
116
                    'optionalArray' => [],
117
                ],
118
            ],
119
            'no subOptionalHash' => [
120
                (object) [
121
                    'value'         => 'value',
122
                    'defaultArray'  => [
123
                        (object) [
124
                            'value'             => 'defaultArray.value',
125
                            'subDefaultHash'    => (object) ['value' => 'defaultArray.subDefaultHash.value'],
126
                            'subRequiredHash'   => (object) ['value' => 'defaultArray.subRequiredHash.value'],
127
                        ],
128
                    ],
129
                    'optionalArray' => [
130
                        (object) [
131
                            'value'             => 'optionalArray.value',
132
                            'subDefaultHash'    => (object) ['value' => 'optionalArray.subDefaultHash.value'],
133
                            'subRequiredHash'   => (object) ['value' => 'optionalArray.subRequiredHash.value'],
134
                        ],
135
                    ],
136
                    'requiredArray' => [
137
                        (object) [
138
                            'value'             => 'requiredArray.value',
139
                            'subDefaultHash'    => (object) ['value' => 'requiredArray.subDefaultHash.value'],
140
                            'subRequiredHash'   => (object) ['value' => 'requiredArray.subRequiredHash.value'],
141
                        ],
142
                    ],
143
                    'notEmptyArray' => [
144
                        (object) [
145
                            'value'             => 'notEmptyArray.value',
146
                            'subDefaultHash'    => (object) ['value' => 'notEmptyArray.subDefaultHash.value'],
147
                            'subRequiredHash'   => (object) ['value' => 'notEmptyArray.subRequiredHash.value'],
148
                        ],
149
                    ],
150
                ],
151
            ],
152
        ];
153
    }
154
155
    /**
156
     * @param object   $data   JSON data
157
     * @param object[] $errors Expected errors
158
     * @return void
159
     *
160
     * @dataProvider dataInvalid
161
     * @group newEmbed
162
     * @group newEmbedInvalid
163
     * @group newEmbedArray
164
     * @group newEmbedArrayInvalid
165
     */
166 View Code Duplication
    public function testInvalid($data, array $errors)
167
    {
168
        $client = static::createRestClient();
169
        $client->post('/testcase/embed-array/', $data);
170
171
        $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
172
        $this->assertEquals(count($client->getResults()), count($errors));
173
174
        foreach ($errors as $error) {
175
            $this->assertContains($error, $client->getResults(), '', false, false);
176
        }
177
    }
178
179
    /**
180
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,array[]>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
181
     */
182
    public function dataInvalid()
183
    {
184
        return [
185
            'empty notEmptyArray' => [
186
                (object) [
187
                    'value'         => 'value',
188
                    'defaultArray'  => [],
189
                    'optionalArray' => [],
190
                    'requiredArray' => [],
191
                    'notEmptyArray' => [],
192
                ],
193
                [
194
                    (object) [
195
                        'message'       => 'There must be a minimum of 1 items in the array',
196
                        'propertyPath'  => 'notEmptyArray',
197
                    ],
198
                ],
199
            ],
200
            'no requiredArray' => [
201
                (object) [
202
                    'value'         => 'value',
203
                    'defaultArray'  => [],
204
                    'optionalArray' => [],
205
                ],
206
                [
207
                    (object) [
208
                        'message'       => 'The property requiredArray is required',
209
                        'propertyPath'  => 'requiredArray',
210
                    ],
211
                ],
212
            ],
213
            'no value' => [
214
                (object) [
215
                    'defaultArray'  => [
216
                        (object) [
217
                            'subDefaultHash'    => (object) ['value' => 'defaultHash.subDefaultHash.value'],
218
                            'subOptionalHash'   => (object) ['value' => 'defaultHash.subOptionalHash.value'],
219
                            'subRequiredHash'   => (object) ['value' => 'defaultHash.subRequiredHash.value'],
220
                        ],
221
                    ],
222
                    'optionalArray'  => [
223
                        (object) [
224
                            'subDefaultHash'    => (object) ['value' => 'optionalHash.subDefaultHash.value'],
225
                            'subOptionalHash'   => (object) ['value' => 'optionalHash.subOptionalHash.value'],
226
                            'subRequiredHash'   => (object) ['value' => 'optionalHash.subRequiredHash.value'],
227
                        ],
228
                    ],
229
                    'requiredArray'  => [
230
                        (object) [
231
                            'subDefaultHash'    => (object) ['value' => 'requiredHash.subDefaultHash.value'],
232
                            'subOptionalHash'   => (object) ['value' => 'requiredHash.subOptionalHash.value'],
233
                            'subRequiredHash'   => (object) ['value' => 'requiredHash.subRequiredHash.value'],
234
                        ],
235
                    ],
236
                    'notEmptyArray'  => [
237
                        (object) [
238
                            'subDefaultHash'    => (object) ['value' => 'notEmptyArray.subDefaultHash.value'],
239
                            'subOptionalHash'   => (object) ['value' => 'notEmptyArray.subOptionalHash.value'],
240
                            'subRequiredHash'   => (object) ['value' => 'notEmptyArray.subRequiredHash.value'],
241
                        ],
242
                    ],
243
                ],
244
                [
245
                    (object) [
246
                        'message'       => 'The property value is required',
247
                        'propertyPath'  => 'value',
248
                    ],
249
                    (object) [
250
                        'message'       => 'The property value is required',
251
                        'propertyPath'  => 'defaultArray[0].value',
252
                    ],
253
                    (object) [
254
                        'message'       => 'The property value is required',
255
                        'propertyPath'  => 'optionalArray[0].value',
256
                    ],
257
                    (object) [
258
                        'message'       => 'The property value is required',
259
                        'propertyPath'  => 'requiredArray[0].value',
260
                    ],
261
                    (object) [
262
                        'message'       => 'The property value is required',
263
                        'propertyPath'  => 'notEmptyArray[0].value',
264
                    ],
265
                ],
266
            ],
267
            'no value at all' => [
268
                (object) [
269
                    'defaultArray'  => [
270
                        (object) [
271
                            'subDefaultHash'    => (object) [],
272
                            'subOptionalHash'   => (object) [],
273
                            'subRequiredHash'   => (object) [],
274
                        ],
275
                    ],
276
                    'optionalArray'  => [
277
                        (object) [
278
                            'subDefaultHash'    => (object) [],
279
                            'subOptionalHash'   => (object) [],
280
                            'subRequiredHash'   => (object) [],
281
                        ],
282
                    ],
283
                    'requiredArray'  => [
284
                        (object) [
285
                            'subDefaultHash'    => (object) [],
286
                            'subOptionalHash'   => (object) [],
287
                            'subRequiredHash'   => (object) [],
288
                        ],
289
                    ],
290
                    'notEmptyArray'  => [
291
                        (object) [
292
                            'subDefaultHash'    => (object) [],
293
                            'subOptionalHash'   => (object) [],
294
                            'subRequiredHash'   => (object) [],
295
                        ],
296
                    ],
297
                ],
298
                [
299
                    (object) [
300
                        'message'       => 'The property value is required',
301
                        'propertyPath'  => 'value',
302
                    ],
303
304
                    (object) [
305
                        'message'       => 'The property value is required',
306
                        'propertyPath'  => 'defaultArray[0].value',
307
                    ],
308
                    (object) [
309
                        'message'       => 'The property value is required',
310
                        'propertyPath'  => 'defaultArray[0].subDefaultHash.value',
311
                    ],
312
                    (object) [
313
                        'message'       => 'The property value is required',
314
                        'propertyPath'  => 'defaultArray[0].subOptionalHash.value',
315
                    ],
316
                    (object) [
317
                        'message'       => 'The property value is required',
318
                        'propertyPath'  => 'defaultArray[0].subRequiredHash.value',
319
                    ],
320
321
                    (object) [
322
                        'message'       => 'The property value is required',
323
                        'propertyPath'  => 'optionalArray[0].value',
324
                    ],
325
                    (object) [
326
                        'message'       => 'The property value is required',
327
                        'propertyPath'  => 'optionalArray[0].subDefaultHash.value',
328
                    ],
329
                    (object) [
330
                        'message'       => 'The property value is required',
331
                        'propertyPath'  => 'optionalArray[0].subOptionalHash.value',
332
                    ],
333
                    (object) [
334
                        'message'       => 'The property value is required',
335
                        'propertyPath'  => 'optionalArray[0].subRequiredHash.value',
336
                    ],
337
338
                    (object) [
339
                        'message'       => 'The property value is required',
340
                        'propertyPath'  => 'requiredArray[0].value',
341
                    ],
342
                    (object) [
343
                        'message'       => 'The property value is required',
344
                        'propertyPath'  => 'requiredArray[0].subDefaultHash.value',
345
                    ],
346
                    (object) [
347
                        'message'       => 'The property value is required',
348
                        'propertyPath'  => 'requiredArray[0].subOptionalHash.value',
349
                    ],
350
                    (object) [
351
                        'message'       => 'The property value is required',
352
                        'propertyPath'  => 'requiredArray[0].subRequiredHash.value',
353
                    ],
354
355
                    (object) [
356
                        'message'       => 'The property value is required',
357
                        'propertyPath'  => 'notEmptyArray[0].value',
358
                    ],
359
                    (object) [
360
                        'message'       => 'The property value is required',
361
                        'propertyPath'  => 'notEmptyArray[0].subDefaultHash.value',
362
                    ],
363
                    (object) [
364
                        'message'       => 'The property value is required',
365
                        'propertyPath'  => 'notEmptyArray[0].subOptionalHash.value',
366
                    ],
367
                    (object) [
368
                        'message'       => 'The property value is required',
369
                        'propertyPath'  => 'notEmptyArray[0].subRequiredHash.value',
370
                    ],
371
                ],
372
            ],
373
            'no requiredHash' => [
374
                (object) [
375
                    'value'         => 'value',
376
                    'defaultArray'  => [
377
                        (object) [
378
                            'value'             => 'defaultArray.value',
379
                            'subDefaultHash'    => (object) ['value' => 'defaultArray.subDefaultHash.value'],
380
                            'subOptionalHash'   => (object) ['value' => 'defaultArray.subOptionalHash.value'],
381
                        ],
382
                    ],
383
                    'optionalArray' => [
384
                        (object) [
385
                            'value'             => 'defaultArray.value',
386
                            'subDefaultHash'    => (object) ['value' => 'optionalArray.subDefaultHash.value'],
387
                            'subOptionalHash'   => (object) ['value' => 'optionalArray.subOptionalHash.value'],
388
                        ],
389
                    ],
390
                    'requiredArray' => [
391
                        (object) [
392
                            'value'             => 'defaultArray.value',
393
                            'subDefaultHash'    => (object) ['value' => 'requiredArray.subDefaultHash.value'],
394
                            'subOptionalHash'   => (object) ['value' => 'requiredArray.subOptionalHash.value'],
395
                        ],
396
                    ],
397
                    'notEmptyArray' => [
398
                        (object) [
399
                            'value'             => 'notEmptyArray.value',
400
                            'subDefaultHash'    => (object) ['value' => 'notEmptyArray.subDefaultHash.value'],
401
                        ],
402
                    ],
403
                ],
404
                [
405
                    (object) [
406
                        'message'       => 'The property subRequiredHash is required',
407
                        'propertyPath'  => 'defaultArray[0].subRequiredHash',
408
                    ],
409
                    (object) [
410
                        'message'       => 'The property subRequiredHash is required',
411
                        'propertyPath'  => 'optionalArray[0].subRequiredHash',
412
                    ],
413
                    (object) [
414
                        'message'       => 'The property subRequiredHash is required',
415
                        'propertyPath'  => 'requiredArray[0].subRequiredHash',
416
                    ],
417
                    (object) [
418
                        'message'       => 'The property subRequiredHash is required',
419
                        'propertyPath'  => 'notEmptyArray[0].subRequiredHash',
420
                    ],
421
                ],
422
            ],
423
            'no defaultHash' => [
424
                (object) [
425
                    'value'         => 'value',
426
                    'defaultArray'  => [
427
                        (object) [
428
                            'value'             => 'defaultArray.value',
429
                            'subOptionalHash'   => (object) ['value' => 'defaultArray.subOptionalHash.value'],
430
                            'subRequiredHash'   => (object) ['value' => 'defaultArray.subRequiredHash.value'],
431
                        ],
432
                    ],
433
                    'optionalArray' => [
434
                        (object) [
435
                            'value'             => 'defaultArray.value',
436
                            'subOptionalHash'   => (object) ['value' => 'optionalArray.subOptionalHash.value'],
437
                            'subRequiredHash'   => (object) ['value' => 'optionalArray.subRequiredHash.value'],
438
                        ],
439
                    ],
440
                    'requiredArray' => [
441
                        (object) [
442
                            'value'             => 'defaultArray.value',
443
                            'subOptionalHash'   => (object) ['value' => 'requiredArray.subOptionalHash.value'],
444
                            'subRequiredHash'   => (object) ['value' => 'requiredArray.subRequiredHash.value'],
445
                        ],
446
                    ],
447
                    'notEmptyArray' => [
448
                        (object) [
449
                            'value'             => 'notEmptyArray.value',
450
                            'subRequiredHash'   => (object) ['value' => 'notEmptyArray.subRequiredHash.value'],
451
                        ],
452
                    ],
453
                ],
454
                [
455
                    (object) [
456
                        'message'       => 'The property subDefaultHash is required',
457
                        'propertyPath'  => 'defaultArray[0].subDefaultHash',
458
                    ],
459
                    (object) [
460
                        'message'       => 'The property subDefaultHash is required',
461
                        'propertyPath'  => 'optionalArray[0].subDefaultHash',
462
                    ],
463
                    (object) [
464
                        'message'       => 'The property subDefaultHash is required',
465
                        'propertyPath'  => 'requiredArray[0].subDefaultHash',
466
                    ],
467
                    (object) [
468
                        'message'       => 'The property subDefaultHash is required',
469
                        'propertyPath'  => 'notEmptyArray[0].subDefaultHash',
470
                    ],
471
                ],
472
            ],
473
        ];
474
    }
475
}
476