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

EmbedHashTest::dataInvalid()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 176
Code Lines 121

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 176
rs 8.2857
cc 1
eloc 121
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
 * EmbedHashTest 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 EmbedHashTest 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 newEmbedHash
26
     * @group newEmbedHashValid
27
     */
28
    public function testValid($data)
29
    {
30
        $client = static::createRestClient();
31
        $client->post('/testcase/embed-hash/', $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
                    'defaultHash'   => (object) [
46
                        'value'             => 'defaultHash.value',
47
                        'subDefaultHash'    => (object) ['value' => 'defaultHash.subDefaultHash.value'],
48
                        'subOptionalHash'   => (object) ['value' => 'defaultHash.subOptionalHash.value'],
49
                        'subRequiredHash'   => (object) ['value' => 'defaultHash.subRequiredHash.value'],
50
                    ],
51
                    'optionalHash'   => (object) [
52
                        'value'             => 'defaultHash.value',
53
                        'subDefaultHash'    => (object) ['value' => 'optionalHash.subDefaultHash.value'],
54
                        'subOptionalHash'   => (object) ['value' => 'optionalHash.subOptionalHash.value'],
55
                        'subRequiredHash'   => (object) ['value' => 'optionalHash.subRequiredHash.value'],
56
                    ],
57
                    'requiredHash'   => (object) [
58
                        'value'             => 'defaultHash.value',
59
                        'subDefaultHash'    => (object) ['value' => 'requiredHash.subDefaultHash.value'],
60
                        'subOptionalHash'   => (object) ['value' => 'requiredHash.subOptionalHash.value'],
61
                        'subRequiredHash'   => (object) ['value' => 'requiredHash.subRequiredHash.value'],
62
                    ],
63
                ],
64
            ],
65
            'no optionalHash' => [
66
                (object) [
67
                    'value'         => 'value',
68
                    'defaultHash'   => (object) [
69
                        'value'             => 'defaultHash.value',
70
                        'subDefaultHash'    => (object) ['value' => 'defaultHash.subDefaultHash.value'],
71
                        'subOptionalHash'   => (object) ['value' => 'defaultHash.subOptionalHash.value'],
72
                        'subRequiredHash'   => (object) ['value' => 'defaultHash.subRequiredHash.value'],
73
                    ],
74
                    'requiredHash'   => (object) [
75
                        'value'             => 'defaultHash.value',
76
                        'subDefaultHash'    => (object) ['value' => 'requiredHash.subDefaultHash.value'],
77
                        'subOptionalHash'   => (object) ['value' => 'requiredHash.subOptionalHash.value'],
78
                        'subRequiredHash'   => (object) ['value' => 'requiredHash.subRequiredHash.value'],
79
                    ],
80
                ],
81
            ],
82
            'no subOptionalHash' => [
83
                (object) [
84
                    'value'         => 'value',
85
                    'defaultHash'   => (object) [
86
                        'value'             => 'defaultHash.value',
87
                        'subDefaultHash'    => (object) ['value' => 'defaultHash.subDefaultHash.value'],
88
                        'subRequiredHash'   => (object) ['value' => 'defaultHash.subRequiredHash.value'],
89
                    ],
90
                    'optionalHash'   => (object) [
91
                        'value'             => 'defaultHash.value',
92
                        'subDefaultHash'    => (object) ['value' => 'optionalHash.subDefaultHash.value'],
93
                        'subRequiredHash'   => (object) ['value' => 'optionalHash.subRequiredHash.value'],
94
                    ],
95
                    'requiredHash'   => (object) [
96
                        'value'             => 'defaultHash.value',
97
                        'subDefaultHash'    => (object) ['value' => 'requiredHash.subDefaultHash.value'],
98
                        'subRequiredHash'   => (object) ['value' => 'requiredHash.subRequiredHash.value'],
99
                    ],
100
                ],
101
            ],
102
        ];
103
    }
104
105
    /**
106
     * @param object   $data   JSON data
107
     * @param object[] $errors Expected errors
108
     * @return void
109
     *
110
     * @dataProvider dataInvalid
111
     * @group newEmbed
112
     * @group newEmbedInvalid
113
     * @group newEmbedHash
114
     * @group newEmbedHashInvalid
115
     */
116 View Code Duplication
    public function testInvalid($data, array $errors)
117
    {
118
        $client = static::createRestClient();
119
        $client->post('/testcase/embed-hash/', $data);
120
121
        $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
122
        $this->assertEquals(count($client->getResults()), count($errors));
123
124
        foreach ($errors as $error) {
125
            $this->assertContains($error, $client->getResults(), '', false, false);
126
        }
127
    }
128
129
    /**
130
     * @return array
131
     */
132
    public function dataInvalid()
133
    {
134
        return [
135
            'no value' => [
136
                (object) [
137
                    'defaultHash'   => (object) [
138
                        'subDefaultHash'    => (object) ['value' => 'defaultHash.subDefaultHash.value'],
139
                        'subOptionalHash'   => (object) ['value' => 'defaultHash.subOptionalHash.value'],
140
                        'subRequiredHash'   => (object) ['value' => 'defaultHash.subRequiredHash.value'],
141
                    ],
142
                    'optionalHash'   => (object) [
143
                        'subDefaultHash'    => (object) ['value' => 'optionalHash.subDefaultHash.value'],
144
                        'subOptionalHash'   => (object) ['value' => 'optionalHash.subOptionalHash.value'],
145
                        'subRequiredHash'   => (object) ['value' => 'optionalHash.subRequiredHash.value'],
146
                    ],
147
                    'requiredHash'   => (object) [
148
                        'subDefaultHash'    => (object) ['value' => 'requiredHash.subDefaultHash.value'],
149
                        'subOptionalHash'   => (object) ['value' => 'requiredHash.subOptionalHash.value'],
150
                        'subRequiredHash'   => (object) ['value' => 'requiredHash.subRequiredHash.value'],
151
                    ],
152
                ],
153
                [
154
                    (object) [
155
                        'message'       => 'The property value is required',
156
                        'propertyPath'  => 'value',
157
                    ],
158
                    (object) [
159
                        'message'       => 'The property value is required',
160
                        'propertyPath'  => 'defaultHash.value',
161
                    ],
162
                    (object) [
163
                        'message'       => 'The property value is required',
164
                        'propertyPath'  => 'optionalHash.value',
165
                    ],
166
                    (object) [
167
                        'message'       => 'The property value is required',
168
                        'propertyPath'  => 'requiredHash.value',
169
                    ],
170
                ],
171
            ],
172
            'no value at all' => [
173
                (object) [
174
                    'defaultHash'   => (object) [
175
                        'subDefaultHash'    => (object) [],
176
                        'subOptionalHash'   => (object) [],
177
                        'subRequiredHash'   => (object) [],
178
                    ],
179
                    'optionalHash'   => (object) [
180
                        'subDefaultHash'    => (object) [],
181
                        'subOptionalHash'   => (object) [],
182
                        'subRequiredHash'   => (object) [],
183
                    ],
184
                    'requiredHash'   => (object) [
185
                        'subDefaultHash'    => (object) [],
186
                        'subOptionalHash'   => (object) [],
187
                        'subRequiredHash'   => (object) [],
188
                    ],
189
                ],
190
                [
191
                    (object) [
192
                        'message'       => 'The property value is required',
193
                        'propertyPath'  => 'value',
194
                    ],
195
196
                    (object) [
197
                        'message'       => 'The property value is required',
198
                        'propertyPath'  => 'defaultHash.value',
199
                    ],
200
                    (object) [
201
                        'message'       => 'The property value is required',
202
                        'propertyPath'  => 'defaultHash.subDefaultHash.value',
203
                    ],
204
                    (object) [
205
                        'message'       => 'The property value is required',
206
                        'propertyPath'  => 'defaultHash.subOptionalHash.value',
207
                    ],
208
                    (object) [
209
                        'message'       => 'The property value is required',
210
                        'propertyPath'  => 'defaultHash.subRequiredHash.value',
211
                    ],
212
213
                    (object) [
214
                        'message'       => 'The property value is required',
215
                        'propertyPath'  => 'optionalHash.value',
216
                    ],
217
                    (object) [
218
                        'message'       => 'The property value is required',
219
                        'propertyPath'  => 'optionalHash.subDefaultHash.value',
220
                    ],
221
                    (object) [
222
                        'message'       => 'The property value is required',
223
                        'propertyPath'  => 'optionalHash.subOptionalHash.value',
224
                    ],
225
                    (object) [
226
                        'message'       => 'The property value is required',
227
                        'propertyPath'  => 'optionalHash.subRequiredHash.value',
228
                    ],
229
230
                    (object) [
231
                        'message'       => 'The property value is required',
232
                        'propertyPath'  => 'requiredHash.value',
233
                    ],
234
                    (object) [
235
                        'message'       => 'The property value is required',
236
                        'propertyPath'  => 'requiredHash.subDefaultHash.value',
237
                    ],
238
                    (object) [
239
                        'message'       => 'The property value is required',
240
                        'propertyPath'  => 'requiredHash.subOptionalHash.value',
241
                    ],
242
                    (object) [
243
                        'message'       => 'The property value is required',
244
                        'propertyPath'  => 'requiredHash.subRequiredHash.value',
245
                    ],
246
                ],
247
            ],
248
            'no requiredHash' => [
249
                (object) [
250
                    'value'         => 'value',
251
                    'defaultHash'   => (object) [
252
                        'value'             => 'defaultHash.value',
253
                        'subDefaultHash'    => (object) ['value' => 'defaultHash.subDefaultHash.value'],
254
                        'subOptionalHash'   => (object) ['value' => 'defaultHash.subOptionalHash.value'],
255
                    ],
256
                    'optionalHash'   => (object) [
257
                        'value'             => 'optionalHash.value',
258
                        'subDefaultHash'    => (object) ['value' => 'optionalHash.subDefaultHash.value'],
259
                        'subOptionalHash'   => (object) ['value' => 'optionalHash.subOptionalHash.value'],
260
                    ],
261
                ],
262
                [
263
                    (object) [
264
                        'message'       => 'The property requiredHash is required',
265
                        'propertyPath'  => 'requiredHash',
266
                    ],
267
                    (object) [
268
                        'message'       => 'The property subRequiredHash is required',
269
                        'propertyPath'  => 'defaultHash.subRequiredHash',
270
                    ],
271
                    (object) [
272
                        'message'       => 'The property subRequiredHash is required',
273
                        'propertyPath'  => 'optionalHash.subRequiredHash',
274
                    ],
275
                ],
276
            ],
277
            'no defaultHash' => [
278
                (object) [
279
                    'value'         => 'value',
280
                    'optionalHash'   => (object) [
281
                        'value'             => 'optionalHash.value',
282
                        'subOptionalHash'   => (object) ['value' => 'optionalHash.subOptionalHash.value'],
283
                        'subRequiredHash'   => (object) ['value' => 'optionalHash.subRequiredHash.value'],
284
                    ],
285
                    'requiredHash'   => (object) [
286
                        'value'             => 'requiredHash.value',
287
                        'subOptionalHash'   => (object) ['value' => 'requiredHash.subOptionalHash.value'],
288
                        'subRequiredHash'   => (object) ['value' => 'requiredHash.subRequiredHash.value'],
289
                    ],
290
                ],
291
                [
292
                    (object) [
293
                        'message'       => 'The property defaultHash is required',
294
                        'propertyPath'  => 'defaultHash',
295
                    ],
296
                    (object) [
297
                        'message'       => 'The property subDefaultHash is required',
298
                        'propertyPath'  => 'optionalHash.subDefaultHash',
299
                    ],
300
                    (object) [
301
                        'message'       => 'The property subDefaultHash is required',
302
                        'propertyPath'  => 'requiredHash.subDefaultHash',
303
                    ],
304
                ],
305
            ],
306
        ];
307
    }
308
}
309