Completed
Push — master ( 8c5aef...11380b )
by Guillaume
03:14
created

EventControllerTest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 407
Duplicated Lines 43 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 3
dl 175
loc 407
rs 10
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
B testPostValide() 0 25 1
A getCampagneId() 0 7 1
A testPostInvalide() 21 21 1
B testPutValide() 0 35 1
B testPutInvalide() 0 27 1
B testPutSansResultat() 25 25 1
B testCGetValideAvecResultats() 25 25 2
A testCGetValideSansResultat() 21 21 1
A testCGetInvalide() 19 19 1
B testGetValideAvecResultats() 0 28 1
A testGetValideSansResultat() 22 22 1
A testGetInvalide() 20 20 1
B testDeleteValide() 0 28 1
A testDeleteSansResultat() 22 22 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Starkerxp\CampagneBundle\Tests\Controller;
4
5
use Starkerxp\StructureBundle\Tests\WebTest;
6
7
class EventControllerTest extends WebTest
8
{
9
10
    /**
11
     * @group event
12
     * @group post
13
     * @group controller
14
     */
15
    public function testPostValide()
16
    {
17
        $this->loadFixtureFiles(
18
            [
19
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
20
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
21
            ]
22
        );
23
        $data = [
24
            //'nom'     => "Mon nom", //exemple
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
        ];
26
        $url = $this->generateUrl(
27
            'starkerxp_campagne.event.post',
28
            [
29
                "campagne_id" => $this->getCampagneId(),
30
            ]
31
        );
32
        $client = $this->getAuthClient();
33
        $client->request('POST', $url, $data);
34
        $response = $client->getResponse();
35
        $this->assertEquals(201, $response->getStatusCode());
36
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
37
        $events = $manager->findAll();
38
        $this->assertCount(1, $events);
39
    }
40
41
    protected function getCampagneId()
42
    {
43
        $repositoryCampagne = $this->getEntityManager()->getRepository("StarkerxpCampagneBundle:Campagne");
44
        $resultats = $repositoryCampagne->findAll();
45
46
        return $resultats[0]->getId();
47
    }
48
49
    /**
50
     * @group event
51
     * @group post
52
     * @group controller
53
     */
54 View Code Duplication
    public function testPostInvalide()
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...
55
    {
56
        $this->loadFixtureFiles(
57
            [
58
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
59
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
60
            ]
61
        );
62
        $url = $this->generateUrl(
63
            'starkerxp_campagne.event.post',
64
            [
65
                "campagne_id" => $this->getCampagneId(),
66
            ]
67
        );
68
        $client = $this->getAuthClient();
69
        $client->request('POST', $url, []);
70
        $response = $client->getResponse();
71
        $this->assertEquals(400, $response->getStatusCode());
72
        $body = json_decode($response->getContent(), true)['payload'];
0 ignored issues
show
Unused Code introduced by
$body is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
73
        //$this->assertArrayHasKey("nom", $body); // Exemple
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
74
    }
75
76
    /**
77
     * @group event
78
     * @group put
79
     * @group controller
80
     */
81
    public function testPutValide()
82
    {
83
        $this->loadFixtureFiles(
84
            [
85
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
86
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
87
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml',
88
            ]
89
        );
90
91
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
92
        $listeEvents = $manager->getRepository()->findAll();
93
        $this->assertCount(1, $listeEvents);
94
        $eventDepart = $manager->toArray($listeEvents[0], [/*'nom'*/]);// Exemple
95
        $data = [
96
            //'nom'     => "Mon nom", //exemple
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
97
        ];
98
        $url = $this->generateUrl(
99
            'starkerxp_campagne.event.put',
100
            [
101
                "campagne_id" => $this->getCampagneId(),
102
                "id"    => $listeEvents[0]->getId(),
103
            ]
104
        );
105
        $client = $this->getAuthClient();
106
        $client->request('PUT', $url, $data);
107
        $response = $client->getResponse();
108
        $this->assertEquals(204, $response->getStatusCode());
109
        $manager->clear();
110
        $events = $manager->findAll();
111
        $this->assertCount(1, $events);
112
        $eventFinal = $manager->toArray($events[0], [/*'nom'*/]);// Exemple
113
        $this->assertNotEquals($eventDepart, $eventFinal);
114
        $this->assertEquals($data, $eventFinal);
115
    }
116
117
    /**
118
     * @group event
119
     * @group put
120
     * @group controller
121
     */
122
    public function testPutInvalide()
123
    {
124
        $this->loadFixtureFiles(
125
            [
126
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
127
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
128
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml',
129
            ]
130
        );
131
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
132
        $listeEvents = $manager->getRepository()->findAll();
133
        $this->assertCount(1, $listeEvents);
134
        $url = $this->generateUrl(
135
            'starkerxp_campagne.event.put',
136
            [
137
                "campagne_id" => $this->getCampagneId(),
138
                "id"    => $listeEvents[0]->getId(),
139
            ]
140
        );
141
        $client = $this->getAuthClient();
142
        $client->request('PUT', $url, []);
143
        $response = $client->getResponse();
144
        $this->assertEquals(400, $response->getStatusCode());
145
        $body = json_decode($response->getContent(), true)['payload'];
0 ignored issues
show
Unused Code introduced by
$body is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
146
        //$this->assertArrayHasKey("nom", $body); // Exemple
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
147
148
    }
149
150
    /**
151
     * @group event
152
     * @group put
153
     * @group controller
154
     */
155 View Code Duplication
    public function testPutSansResultat()
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...
156
    {
157
        $this->loadFixtureFiles(
158
            [
159
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
160
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
161
            ]
162
        );
163
        $data = [
164
            //'nom'     => "Mon nom", //exemple
0 ignored issues
show
Unused Code Comprehensibility introduced by
58% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
165
        ];
166
        $url = $this->generateUrl(
167
            'starkerxp_campagne.event.put',
168
            [
169
                "campagne_id" => $this->getCampagneId(),
170
                "id"    => 404,
171
            ]
172
        );
173
        $client = $this->getAuthClient();
174
        $client->request('PUT', $url, $data);
175
        $response = $client->getResponse();
176
        $this->assertEquals(404, $response->getStatusCode());
177
        $body = json_decode($response->getContent(), true);
178
        $this->assertNotEmpty($body);
179
    }
180
181
    /**
182
     * @group event
183
     * @group cget
184
     * @group controller
185
     */
186 View Code Duplication
    public function testCGetValideAvecResultats()
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...
187
    {
188
        $this->loadFixtureFiles(
189
            [
190
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
191
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
192
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/EventManager.yml',
193
            ]
194
        );
195
        $url = $this->generateUrl(
196
            'starkerxp_campagne.event.cget',
197
            [
198
                "campagne_id" => $this->getCampagneId(),
199
            ]
200
        );
201
        $client = $this->getAuthClient();
202
        $client->request('GET', $url, []);
203
        $response = $client->getResponse();
204
        $this->assertEquals(200, $response->getStatusCode());
205
        $body = json_decode($response->getContent(), true);
206
        $this->assertCount(10, $body);
207
        foreach ($body as $element) {
0 ignored issues
show
Unused Code introduced by
This foreach statement is empty and can be removed.

This check looks for foreach loops that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

Consider removing the loop.

Loading history...
208
            //$this->assertArrayHasKey("nom", $body); // Exemple
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
209
        }
210
    }
211
212
    /**
213
     * @group event
214
     * @group cget
215
     * @group controller
216
     */
217 View Code Duplication
    public function testCGetValideSansResultat()
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...
218
    {
219
        $this->loadFixtureFiles(
220
            [
221
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
222
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
223
            ]
224
        );
225
        $url = $this->generateUrl(
226
            'starkerxp_campagne.event.cget',
227
            [
228
                "campagne_id" => $this->getCampagneId(),
229
            ]
230
        );
231
        $client = $this->getAuthClient();
232
        $client->request('GET', $url, []);
233
        $response = $client->getResponse();
234
        $this->assertEquals(200, $response->getStatusCode());
235
        $body = json_decode($response->getContent(), true);
236
        $this->assertCount(0, $body);
237
    }
238
239
    /**
240
     * @group event
241
     * @group cget
242
     * @group controller
243
     */
244 View Code Duplication
    public function testCGetInvalide()
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...
245
    {
246
        $this->loadFixtureFiles(
247
            [
248
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
249
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
250
            ]
251
        );
252
        $url = $this->generateUrl(
253
            'starkerxp_campagne.event.cget',
254
            [
255
                "campagne_id" => $this->getCampagneId(),
256
            ]
257
        );
258
        $client = $this->getAuthClient();
259
        $client->request('GET', $url, ["filter_erreur" => "+h"]);
260
        $response = $client->getResponse();
261
        $this->assertEquals(400, $response->getStatusCode());
262
    }
263
264
    /**
265
     * @group event
266
     * @group get
267
     * @group controller
268
     */
269
    public function testGetValideAvecResultats()
270
    {
271
        $this->loadFixtureFiles(
272
            [
273
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
274
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
275
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/EventManager.yml',
276
            ]
277
        );
278
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
279
        $listeEvents = $manager->getRepository()->findAll();
280
        $this->assertCount(10, $listeEvents);
281
        $url = $this->generateUrl(
282
            'starkerxp_campagne.event.get',
283
            [
284
                "campagne_id" => $this->getCampagneId(),
285
                "id"    => $listeEvents[0]->getId(),
286
            ]
287
        );
288
        $client = $this->getAuthClient();
289
        $client->request('GET', $url, []);
290
        $response = $client->getResponse();
291
        $this->assertEquals(200, $response->getStatusCode());
292
        $body = json_decode($response->getContent(), true);
293
        $this->assertCount(2, $body);
294
        $this->assertArrayHasKey("id", $body); // Exemple
295
        $this->assertArrayHasKey("campagne_id", $body); // Exemple
296
    }
297
298
    /**
299
     * @group event
300
     * @group get
301
     * @group controller
302
     */
303 View Code Duplication
    public function testGetValideSansResultat()
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...
304
    {
305
        $this->loadFixtureFiles(
306
            [
307
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
308
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
309
            ]
310
        );
311
        $url = $this->generateUrl(
312
            'starkerxp_campagne.event.get',
313
            [
314
                "campagne_id" => $this->getCampagneId(),
315
                "id"    => 404,
316
            ]
317
        );
318
        $client = $this->getAuthClient();
319
        $client->request('GET', $url, []);
320
        $response = $client->getResponse();
321
        $this->assertEquals(404, $response->getStatusCode());
322
        $body = json_decode($response->getContent(), true);
323
        $this->assertNotEmpty($body);
324
    }
325
326
    /**
327
     * @group event
328
     * @group get
329
     * @group controller
330
     */
331 View Code Duplication
    public function testGetInvalide()
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...
332
    {
333
        $this->loadFixtureFiles(
334
            [
335
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
336
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
337
            ]
338
        );
339
        $url = $this->generateUrl(
340
            'starkerxp_campagne.event.get',
341
            [
342
                "campagne_id" => $this->getCampagneId(),
343
                "id"    => 500,
344
            ]
345
        );
346
        $client = $this->getAuthClient();
347
        $client->request('GET', $url, ["filter_erreur" => "+h"]);
348
        $response = $client->getResponse();
349
        $this->assertEquals(400, $response->getStatusCode());
350
    }
351
352
    /**
353
     * @group event
354
     * @group delete
355
     * @group controller
356
     */
357
    public function testDeleteValide()
358
    {
359
360
        $this->loadFixtureFiles(
361
            [
362
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
363
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
364
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml',
365
            ]
366
        );
367
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
368
        $listeEvents = $manager->getRepository()->findAll();
369
        $this->assertCount(1, $listeEvents);
370
        $url = $this->generateUrl(
371
            'starkerxp_campagne.event.delete',
372
            [
373
                "campagne_id" => $this->getCampagneId(),
374
                "id"    => $listeEvents[0]->getId(),
375
            ]
376
        );
377
        $client = $this->getAuthClient();
378
        $client->request('DELETE', $url);
379
        $response = $client->getResponse();
380
        $this->assertEquals(204, $response->getStatusCode());
381
        $manager->clear();
382
        $events = $manager->findAll();
383
        $this->assertCount(0, $events);
384
    }
385
386
    /**
387
     * @group event
388
     * @group delete
389
     * @group controller
390
     */
391 View Code Duplication
    public function testDeleteSansResultat()
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...
392
    {
393
        $this->loadFixtureFiles(
394
            [
395
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
396
                '@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml',
397
            ]
398
        );
399
        $url = $this->generateUrl(
400
            'starkerxp_campagne.event.delete',
401
            [
402
                "campagne_id" => $this->getCampagneId(),
403
                "id"    => 404,
404
            ]
405
        );
406
        $client = $this->getAuthClient();
407
        $client->request('DELETE', $url, []);
408
        $response = $client->getResponse();
409
        $this->assertEquals(404, $response->getStatusCode());
410
        $body = json_decode($response->getContent(), true);
411
        $this->assertNotEmpty($body);
412
    }
413
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
414