Completed
Push — feature/other-validation ( 01c6ab...a6eaef )
by Narcotic
09:55
created

EmbedArrayTest::testValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
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
1 ignored issue
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...
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)
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

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