Completed
Push — master ( cd8c72...c8cad1 )
by Guillaume
03:42
created

EventControllerTest::testCGetValideSansResultat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
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
            ]
21
        );
22
        $data = [
23
            //'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...
24
        ];
25
        $client = $this->getAuthClient();
26
        $client->request('POST', '/campagnes/events', $data);
27
        $response = $client->getResponse();
28
        $this->assertEquals(201, $response->getStatusCode());
29
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
30
        $Events = $manager->findAll();
31
        $this->assertCount(1, $Events);
32
    }
33
34
    /**
35
     * @group event
36
     * @group post
37
     * @group controller
38
     */
39 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...
40
    {
41
        $this->loadFixtureFiles(
42
            [
43
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
44
            ]
45
        );
46
        $client = $this->getAuthClient();
47
        $client->request('POST', '/campagnes/events', []);
48
        $response = $client->getResponse();
49
        $this->assertEquals(400, $response->getStatusCode());
50
        $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...
51
        //$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...
52
    }
53
54
55
    /**
56
     * @group event
57
     * @group put
58
     * @group controller
59
     */
60
    public function testPutValide()
61
    {
62
        $this->loadFixtureFiles(
63
            [
64
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
65
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml',
66
            ]
67
        );
68
69
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
70
        $listeEvents = $manager->getRepository()->findAll();
71
        $this->assertCount(1, $listeEvents);
72
        $EventDepart = $manager->toArray($listeEvents[0], [/*'nom'*/]);// Exemple
73
        $data = [
74
            //'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...
75
        ];
76
        $client = $this->getAuthClient();
77
        $client->request('PUT', '/campagnes/events/'.$listeEvents[0]->getId(), $data);
78
        $response = $client->getResponse();
79
        $this->assertEquals(204, $response->getStatusCode());
80
        $manager->clear();
81
        $Events = $manager->findAll();
82
        $this->assertCount(1, $Events);
83
        $EventFinal = $manager->toArray($Events[0], [/*'nom'*/]);// Exemple
84
        $this->assertNotEquals($EventDepart, $EventFinal);
85
        $this->assertEquals($data, $EventFinal);
86
    }
87
88
    /**
89
     * @group event
90
     * @group put
91
     * @group controller
92
     */
93
    public function testPutInvalide()
94
    {
95
        $this->loadFixtureFiles(
96
            [
97
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
98
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml',
99
            ]
100
        );
101
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
102
        $listeEvents = $manager->getRepository()->findAll();
103
        $this->assertCount(1, $listeEvents);
104
        $client = $this->getAuthClient();
105
        $client->request('PUT', '/campagnes/events/'.$listeEvents[0]->getId(), []);
106
        $response = $client->getResponse();
107
        $this->assertEquals(400, $response->getStatusCode());
108
        $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...
109
        //$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...
110
111
    }
112
113
    /**
114
     * @group event
115
     * @group put
116
     * @group controller
117
     */
118 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...
119
    {
120
        $this->loadFixtureFiles(
121
            [
122
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
123
            ]
124
        );
125
        $data = [
126
            //'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...
127
        ];
128
        $client = $this->getAuthClient();
129
        $client->request('PUT', '/campagnes/events/404', $data);
130
        $response = $client->getResponse();
131
        $this->assertEquals(404, $response->getStatusCode());
132
        $body = json_decode($response->getContent(), true);
133
        $this->assertNotEmpty($body);
134
    }
135
136
137
    /**
138
     * @group event
139
     * @group cget
140
     * @group controller
141
     */
142 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...
143
    {
144
        $this->loadFixtureFiles(
145
            [
146
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
147
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/EventManager.yml',
148
            ]
149
        );
150
        $client = $this->getAuthClient();
151
        $client->request('GET', '/campagnes/events', []);
152
        $response = $client->getResponse();
153
        $this->assertEquals(200, $response->getStatusCode());
154
        $body = json_decode($response->getContent(), true);
155
        $this->assertCount(10, $body);
156
        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...
157
            //$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...
158
        }
159
    }
160
161
    /**
162
     * @group event
163
     * @group cget
164
     * @group controller
165
     */
166 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...
167
    {
168
        $this->loadFixtureFiles(
169
            [
170
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
171
            ]
172
        );
173
        $client = $this->getAuthClient();
174
        $client->request('GET', '/campagnes/events', []);
175
        $response = $client->getResponse();
176
        $this->assertEquals(200, $response->getStatusCode());
177
        $body = json_decode($response->getContent(), true);
178
        $this->assertCount(0, $body);
179
    }
180
181
    /**
182
     * @group event
183
     * @group cget
184
     * @group controller
185
     */
186
    public function testCGetInvalide()
187
    {
188
        $this->loadFixtureFiles(
189
            [
190
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
191
            ]
192
        );
193
        $client = $this->getAuthClient();
194
        $client->request('GET', '/campagnes/events', ["filter_erreur" => "+h"]);
195
        $response = $client->getResponse();
196
        $this->assertEquals(400, $response->getStatusCode());
197
    }
198
199
    /**
200
     * @group event
201
     * @group get
202
     * @group controller
203
     */
204 View Code Duplication
    public function testGetValideAvecResultats()
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...
205
    {
206
        $this->loadFixtureFiles(
207
            [
208
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
209
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/EventManager.yml',
210
            ]
211
        );
212
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
213
        $listeEvents = $manager->getRepository()->findAll();
214
        $this->assertCount(10, $listeEvents);
215
        $client = $this->getAuthClient();
216
        $client->request('GET', '/campagnes/events/'.$listeEvents[0]->getId(), []);
217
        $response = $client->getResponse();
218
        $this->assertEquals(200, $response->getStatusCode());
219
        $body = json_decode($response->getContent(), true);
220
        $this->assertCount(5, $body);
221
        //$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...
222
    }
223
224
    /**
225
     * @group event
226
     * @group get
227
     * @group controller
228
     */
229 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...
230
    {
231
        $this->loadFixtureFiles(
232
            [
233
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
234
            ]
235
        );
236
        $client = $this->getAuthClient();
237
        $client->request('GET', '/campagnes/events/404', []);
238
        $response = $client->getResponse();
239
        $this->assertEquals(404, $response->getStatusCode());
240
        $body = json_decode($response->getContent(), true);
241
        $this->assertNotEmpty($body);
242
    }
243
244
    /**
245
     * @group event
246
     * @group get
247
     * @group controller
248
     */
249 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...
250
    {
251
        $this->loadFixtureFiles(
252
            [
253
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
254
            ]
255
        );
256
        $client = $this->getAuthClient();
257
        $client->request('GET', '/campagnes/events/500', ["filter_erreur" => "+h"]);
258
        $response = $client->getResponse();
259
        $this->assertEquals(400, $response->getStatusCode());
260
    }
261
262
    /**
263
     * @group event
264
     * @group delete
265
     * @group controller
266
     */
267 View Code Duplication
    public function testDeleteValide()
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...
268
    {
269
270
        $this->loadFixtureFiles(
271
            [
272
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
273
                '@StarkerxpCampagneBundle/Tests/DataFixtures/EventManager/DefaultEvent.yml',
274
            ]
275
        );
276
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.event');
277
        $listeEvents = $manager->getRepository()->findAll();
278
        $this->assertCount(1, $listeEvents);
279
        $client = $this->getAuthClient();
280
        $client->request('DELETE', '/campagnes/events/'.$listeEvents[0]->getId());
281
        $response = $client->getResponse();
282
        $this->assertEquals(204, $response->getStatusCode());
283
        $manager->clear();
284
        $Events = $manager->findAll();
285
        $this->assertCount(0, $Events);
286
    }
287
288
    /**
289
     * @group event
290
     * @group delete
291
     * @group controller
292
     */
293 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...
294
    {
295
        $this->loadFixtureFiles(
296
            [
297
                '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
298
            ]
299
        );
300
        $client = $this->getAuthClient();
301
        $client->request('DELETE', '/campagnes/events/404', []);
302
        $response = $client->getResponse();
303
        $this->assertEquals(404, $response->getStatusCode());
304
        $body = json_decode($response->getContent(), true);
305
        $this->assertNotEmpty($body);
306
    }
307
}
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...
308