Completed
Push — master ( 751246...4d4e9b )
by Lucas
10:58
created

testPostWithoutFieldInOptionalHash()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 48
Code Lines 32

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 48
rs 9.125
cc 1
eloc 32
nc 1
nop 0
1
<?php
2
/**
3
 * RequiredHashControllerTest 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 RequiredHashControllerTest extends RestTestCase
17
{
18
    /**
19
     * load fixtures
20
     *
21
     * @return void
22
     */
23
    public function setUp()
24
    {
25
        if (!class_exists('GravitonDyn\TestCaseRequiredHashBundle\DataFixtures\MongoDB\LoadTestCaseRequiredHashData')) {
26
            $this->markTestSkipped('TestCaseRequiredHashData definition is not loaded');
27
        }
28
29
        $this->loadFixtures(
30
            ['GravitonDyn\TestCaseRequiredHashBundle\DataFixtures\MongoDB\LoadTestCaseRequiredHashData'],
31
            null,
32
            'doctrine_mongodb'
33
        );
34
    }
35
36
    /**
37
     * Test POST method with optional hash
38
     *
39
     * @return void
40
     */
41
    public function testPostWithOptionalHash()
42
    {
43
        $data = [
44
            'name'         => __METHOD__,
45
            'optionalHash' => [
46
                'name'     => 'abc',
47
                'value'    => 123,
48
                'optional' => '2015-09-03T12:00:00+0000',
49
50
                'optionalSubHash' => [
51
                    'name'     => 'abc',
52
                    'value'    => 123,
53
                    'optional' => '2015-09-03T12:00:00+0000',
54
                ],
55
                'requiredSubHash' => [
56
                    'name'     => 'abc',
57
                    'value'    => 123,
58
                    'optional' => '2015-09-03T12:00:00+0000',
59
                ],
60
            ],
61
            'requiredHash' => [
62
                'name'     => 'abc',
63
                'value'    => 123,
64
                'optional' => '2015-09-03T12:00:00+0000',
65
66
                'optionalSubHash' => [
67
                    'name'     => 'abc',
68
                    'value'    => 123,
69
                    'optional' => '2015-09-03T12:00:00+0000',
70
                ],
71
                'requiredSubHash' => [
72
                    'name'     => 'abc',
73
                    'value'    => 123,
74
                    'optional' => '2015-09-03T12:00:00+0000',
75
                ],
76
            ],
77
        ];
78
79
        $client = static::createRestClient();
80
        $client->post('/testcase/requiredhash/', $data);
81
        $this->assertEquals(Response::HTTP_CREATED, $client->getResponse()->getStatusCode());
82
        $this->assertEmpty($client->getResults());
83
    }
84
85
    /**
86
     * Test POST method without optional hash
87
     *
88
     * @return void
89
     */
90
    public function testPostWithoutOptionalHash()
91
    {
92
        $data = [
93
            'name'         => __METHOD__,
94
            'requiredHash' => [
95
                'name'     => 'abc',
96
                'value'    => 123,
97
                'optional' => '2015-09-03T12:00:00+0000',
98
99
                'requiredSubHash' => [
100
                    'name'     => 'abc',
101
                    'value'    => 123,
102
                    'optional' => '2015-09-03T12:00:00+0000',
103
                ],
104
            ],
105
        ];
106
107
        $client = static::createRestClient();
108
        $client->post('/testcase/requiredhash/', $data);
109
        $this->assertEquals(Response::HTTP_CREATED, $client->getResponse()->getStatusCode());
110
        $this->assertEmpty($client->getResults());
111
    }
112
113
    /**
114
     * Test POST method without field in optional hash
115
     *
116
     * @return void
117
     */
118
    public function testPostWithoutFieldInOptionalHash()
119
    {
120
        $data = [
121
            'name'         => __METHOD__,
122
            'optionalHash' => [
123
                'name'     => 'abc',
124
            ],
125
            'requiredHash' => [
126
                'name'     => 'abc',
127
                'value'    => 123,
128
                'optional' => '2015-09-03T12:00:00+0000',
129
130
                'optionalSubHash' => [
131
                    'name'     => 'abc',
132
                ],
133
                'requiredSubHash' => [
134
                    'name'     => 'abc',
135
                    'value'    => 123,
136
                    'optional' => '2015-09-03T12:00:00+0000',
137
                ],
138
            ],
139
        ];
140
141
        $client = static::createRestClient();
142
        $client->post('/testcase/requiredhash/', $data);
143
        $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
144
        $this->assertEquals(
145
            [
146
                (object) [
147
                    'propertyPath'  => 'data.optionalHash.value',
148
                    'message'       => 'This value should not be blank.',
149
                ],
150
                (object) [
151
                    'propertyPath'  => 'data.optionalHash.requiredSubHash.name',
152
                    'message'       => 'This value should not be blank.',
153
                ],
154
                (object) [
155
                    'propertyPath'  => 'data.optionalHash.requiredSubHash.value',
156
                    'message'       => 'This value should not be blank.',
157
                ],
158
                (object) [
159
                    'propertyPath'  => 'data.requiredHash.optionalSubHash.value',
160
                    'message'       => 'This value should not be blank.',
161
                ],
162
            ],
163
            $client->getResults()
164
        );
165
    }
166
167
    /**
168
     * Test POST method without required hash
169
     *
170
     * @return void
171
     */
172
    public function testPostWithoutRequiredHash()
173
    {
174
        $data = [
175
            'name' => __METHOD__,
176
        ];
177
178
        $client = static::createRestClient();
179
        $client->post('/testcase/requiredhash/', $data);
180
        $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
181
        $this->assertEquals(
182
            [
183
                (object) [
184
                    'propertyPath'  => 'data.requiredHash.name',
185
                    'message'       => 'This value should not be blank.',
186
                ],
187
                (object) [
188
                    'propertyPath'  => 'data.requiredHash.value',
189
                    'message'       => 'This value should not be blank.',
190
                ],
191
                (object) [
192
                    'propertyPath'  => 'data.requiredHash.requiredSubHash.name',
193
                    'message'       => 'This value should not be blank.',
194
                ],
195
                (object) [
196
                    'propertyPath'  => 'data.requiredHash.requiredSubHash.value',
197
                    'message'       => 'This value should not be blank.',
198
                ],
199
            ],
200
            $client->getResults()
201
        );
202
    }
203
204
    /**
205
     * Test POST method with empty optional hash
206
     *
207
     * @return void
208
     */
209
    public function testPostWithEmptyOptionalHash()
210
    {
211
        $data = [
212
            'name'         => __METHOD__,
213
            'optionalHash' => [
214
                'name'     => null,
215
                'value'    => null,
216
                'optional' => null,
217
            ],
218
            'requiredHash' => [
219
                'name'     => 'abc',
220
                'value'    => 123,
221
                'optional' => '2015-09-03T12:00:00+0000',
222
            ],
223
        ];
224
225
        $client = static::createRestClient();
226
        $client->post('/testcase/requiredhash/', $data);
227
        $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
228
        $this->assertEquals(
229
            [
230
                (object) [
231
                    'propertyPath'  => 'data.optionalHash.name',
232
                    'message'       => 'This value should not be blank.',
233
                ],
234
                (object) [
235
                    'propertyPath'  => 'data.optionalHash.value',
236
                    'message'       => 'This value should not be blank.',
237
                ],
238
                (object) [
239
                    'propertyPath'  => 'data.optionalHash.requiredSubHash.name',
240
                    'message'       => 'This value should not be blank.',
241
                ],
242
                (object) [
243
                    'propertyPath'  => 'data.optionalHash.requiredSubHash.value',
244
                    'message'       => 'This value should not be blank.',
245
                ],
246
                (object) [
247
                    'propertyPath'  => 'data.requiredHash.requiredSubHash.name',
248
                    'message'       => 'This value should not be blank.',
249
                ],
250
                (object) [
251
                    'propertyPath'  => 'data.requiredHash.requiredSubHash.value',
252
                    'message'       => 'This value should not be blank.',
253
                ],
254
            ],
255
            $client->getResults()
256
        );
257
    }
258
259
    /**
260
     * Test POST method with empty required hash
261
     *
262
     * @return void
263
     */
264
    public function testPostWithEmptyRequiredHash()
265
    {
266
        $data = [
267
            'name'         => __METHOD__,
268
            'requiredHash' => [
269
                'name'     => null,
270
                'value'    => null,
271
                'optional' => null,
272
            ],
273
        ];
274
275
        $client = static::createRestClient();
276
        $client->post('/testcase/requiredhash/', $data);
277
        $this->assertEquals(Response::HTTP_BAD_REQUEST, $client->getResponse()->getStatusCode());
278
        $this->assertEquals(
279
            [
280
                (object) [
281
                    'propertyPath'  => 'data.requiredHash.name',
282
                    'message'       => 'This value should not be blank.',
283
                ],
284
                (object) [
285
                    'propertyPath'  => 'data.requiredHash.value',
286
                    'message'       => 'This value should not be blank.',
287
                ],
288
                (object) [
289
                    'propertyPath'  => 'data.requiredHash.requiredSubHash.name',
290
                    'message'       => 'This value should not be blank.',
291
                ],
292
                (object) [
293
                    'propertyPath'  => 'data.requiredHash.requiredSubHash.value',
294
                    'message'       => 'This value should not be blank.',
295
                ],
296
            ],
297
            $client->getResults()
298
        );
299
    }
300
301
    /**
302
     * check that schema does not contain realId artefacts
303
     *
304
     * @return void
305
     */
306
    public function testCollectionHasNoRealId()
0 ignored issues
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...
307
    {
308
        $client = static::createRestclient();
309
        $client->request('GET', '/schema/testcase/requiredhash/collection');
310
311
        $response = $client->getResponse();
312
313
        $this->assertEquals(Response::HTTP_OK, $response->getStatusCode());
314
        $this->assertNotContains('realId', $response->getContent());
315
    }
316
}
317