Completed
Push — master ( 4be93f...79933c )
by Guillaume
11:24
created

testGetValideAvecResultats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

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 11
nc 1
nop 0
1
<?php
2
3
namespace Starkerxp\CampagneBundle\Tests\Controller;
4
5
use Starkerxp\StructureBundle\Tests\WebTest;
6
7 View Code Duplication
class CampagneControllerTest extends WebTest
0 ignored issues
show
Duplication introduced by
This class 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...
8
{
9
10
    /**
11
     * @group campagne
12
     * @group post
13
     * @group controller
14
     */
15
    public function testPostValide()
16
    {
17
        $data = [
18
            //'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...
19
        ];
20
        $client = static::createClient();
21
        $client->request('POST', '/campagnes', $data);
22
        $response = $client->getResponse();
23
        $this->assertEquals(201, $response->getStatusCode());
24
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.campagne');
25
        $Campagnes = $manager->findAll();
26
        $this->assertCount(1, $Campagnes);
27
    }
28
29
    /**
30
     * @group campagne
31
     * @group post
32
     * @group controller
33
     */
34
    public function testPostInvalide()
35
    {
36
        $client = static::createClient();
37
        $client->request('POST', '/campagnes', []);
38
        $response = $client->getResponse();
39
        $this->assertEquals(400, $response->getStatusCode());
40
        $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...
41
        //$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...
42
    }
43
44
45
    /**
46
     * @group campagne
47
     * @group put
48
     * @group controller
49
     */
50
    public function testPutValide()
51
    {
52
        $this->loadFixtureFiles(['@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml']);
53
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.campagne');
54
        $listeCampagnes = $manager->getRepository()->findAll();
55
        $this->assertCount(1, $listeCampagnes);
56
        $CampagneDepart = $manager->toArray($listeCampagnes[0], [/*'nom'*/]);// Exemple
57
        $data = [
58
            //'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...
59
        ];
60
        $client = static::createClient();
61
        $client->request('PUT', '/campagnes/'.$listeCampagnes[0]->getId(), $data);
62
        $response = $client->getResponse();
63
        $this->assertEquals(204, $response->getStatusCode());
64
        $manager->clear();
65
        $Campagnes = $manager->findAll();
66
        $this->assertCount(1, $Campagnes);
67
        $CampagneFinal = $manager->toArray($Campagnes[0], [/*'nom'*/]);// Exemple
68
        $this->assertNotEquals($CampagneDepart, $CampagneFinal);
69
        $this->assertEquals($data, $CampagneFinal);
70
    }
71
72
    /**
73
     * @group campagne
74
     * @group put
75
     * @group controller
76
     */
77
    public function testPutInvalide()
78
    {
79
        $this->loadFixtureFiles(['@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml']);
80
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.campagne');
81
        $listeCampagnes = $manager->getRepository()->findAll();
82
        $this->assertCount(1, $listeCampagnes);
83
        $client = static::createClient();
84
        $client->request('PUT', '/campagnes/'.$listeCampagnes[0]->getId(), []);
85
        $response = $client->getResponse();
86
        $this->assertEquals(400, $response->getStatusCode());
87
        $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...
88
        //$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...
89
        
90
    }
91
92
    /**
93
     * @group campagne
94
     * @group put
95
     * @group controller
96
     */
97
    public function testPutSansResultat()
98
    {
99
        $data = [
100
            //'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...
101
        ];
102
        $client = static::createClient();
103
        $client->request('PUT', '/campagnes/404', $data);
104
        $response = $client->getResponse();
105
        $this->assertEquals(404, $response->getStatusCode());
106
        $body = json_decode($response->getContent(), true);
107
        $this->assertNotEmpty($body);
108
    }
109
110
111
    /**
112
     * @group campagne
113
     * @group cget
114
     * @group controller
115
     */
116
    public function testCGetValideAvecResultats()
117
    {
118
        $this->loadFixtureFiles(['@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/CampagneManager.yml']);
119
        $client = static::createClient();
120
        $client->request('GET', '/campagnes', []);
121
        $response = $client->getResponse();
122
        $this->assertEquals(200, $response->getStatusCode());
123
        $body = json_decode($response->getContent(), true);
124
        $this->assertCount(10, $body);
125
        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...
126
            //$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...
127
        }
128
    }
129
130
    /**
131
     * @group campagne
132
     * @group cget
133
     * @group controller
134
     */
135
    public function testCGetValideSansResultat()
136
    {
137
        $client = static::createClient();
138
        $client->request('GET', '/campagnes', []);
139
        $response = $client->getResponse();
140
        $this->assertEquals(200, $response->getStatusCode());
141
        $body = json_decode($response->getContent(), true);
142
        $this->assertCount(0, $body);
143
    }
144
145
    /**
146
     * @group campagne
147
     * @group cget
148
     * @group controller
149
     */
150
    public function testCGetInvalide()
151
    {
152
        $client = static::createClient();
153
        $client->request('GET', '/campagnes', ["filter_erreur" => "+h"]);
154
        $response = $client->getResponse();
155
        $this->assertEquals(400, $response->getStatusCode());
156
    }
157
158
    /**
159
     * @group campagne
160
     * @group get
161
     * @group controller
162
     */
163
    public function testGetValideAvecResultats()
164
    {
165
        $this->loadFixtureFiles(['@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/CampagneManager.yml']);
166
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.campagne');
167
        $listeCampagnes = $manager->getRepository()->findAll();
168
        $this->assertCount(10, $listeCampagnes);
169
        $client = static::createClient();
170
        $client->request('GET', '/campagnes/'.$listeCampagnes[0]->getId(), []);
171
        $response = $client->getResponse();
172
        $this->assertEquals(200, $response->getStatusCode());
173
        $body = json_decode($response->getContent(), true);
174
        $this->assertCount(5, $body);
175
        //$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...
176
    }
177
178
    /**
179
     * @group campagne
180
     * @group get
181
     * @group controller
182
     */
183
    public function testGetValideSansResultat()
184
    {
185
        $client = static::createClient();
186
        $client->request('GET', '/campagnes/404', []);
187
        $response = $client->getResponse();
188
        $this->assertEquals(404, $response->getStatusCode());
189
        $body = json_decode($response->getContent(), true);
190
        $this->assertNotEmpty($body);
191
    }
192
193
    /**
194
     * @group campagne
195
     * @group get
196
     * @group controller
197
     */
198
    public function testGetInvalide()
199
    {
200
        $client = static::createClient();
201
        $client->request('GET', '/campagnes/500', ["filter_erreur" => "+h"]);
202
        $response = $client->getResponse();
203
        $this->assertEquals(400, $response->getStatusCode());
204
    }
205
206
    /**
207
     * @group campagne
208
     * @group delete
209
     * @group controller
210
     */
211
    public function testDeleteValide()
212
    {
213
        $this->loadFixtureFiles(['@StarkerxpCampagneBundle/Tests/DataFixtures/CampagneManager/DefaultCampagne.yml']);
214
        $manager = $this->getContainer()->get('starkerxp_campagne.manager.campagne');
215
        $listeCampagnes = $manager->getRepository()->findAll();
216
        $this->assertCount(1, $listeCampagnes);
217
        $client = static::createClient();
218
        $client->request('DELETE', '/campagnes/'.$listeCampagnes[0]->getId());
219
        $response = $client->getResponse();
220
        $this->assertEquals(204, $response->getStatusCode());
221
        $manager->clear();
222
        $Campagnes = $manager->findAll();
223
        $this->assertCount(0, $Campagnes);
224
    }
225
226
    /**
227
     * @group campagne
228
     * @group delete
229
     * @group controller
230
     */
231
    public function testDeleteSansResultat()
232
    {
233
        $client = static::createClient();
234
        $client->request('DELETE', '/campagnes/404', []);
235
        $response = $client->getResponse();
236
        $this->assertEquals(404, $response->getStatusCode());
237
        $body = json_decode($response->getContent(), true);
238
        $this->assertNotEmpty($body);
239
    }
240
}
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...
241