Completed
Push — master ( 778ba1...db4111 )
by Guillaume
02:44
created

LeadControllerTest::testPutSansResultat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace Starkerxp\LeadBundle\Tests\Controller;
4
5
use Starkerxp\StructureBundle\Tests\WebTest;
6
7
class LeadControllerTest extends WebTest
8
{
9
10
    /**
11
     * @group lead
12
     * @group post
13
     * @group controller
14
     */
15
    public function testPostValide()
16
    {
17
        $this->loadFixtureFiles([
18
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
19
        ]);
20
        $data = [
21
            //'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...
22
        ];
23
		$url = $this->generateUrl(
24
            'starkerxp_lead.lead.post',
25
            []
26
        );
27
        $client = $this->getAuthClient();
28
        $client->request('POST', $url, $data);
29
        $response = $client->getResponse();
30
        $this->assertEquals(201, $response->getStatusCode());
31
        $manager = $this->getContainer()->get('starkerxp_lead.manager.leadaction');
32
        $LeadActions = $manager->findAll();
33
        $this->assertCount(1, $LeadActions);
34
    }
35
36
    /**
37
     * @group lead
38
     * @group post
39
     * @group controller
40
     */
41 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...
42
    {
43
        $this->loadFixtureFiles([
44
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
45
        ]);
46
		$url = $this->generateUrl(
47
            'starkerxp_lead.lead.post',
48
            []
49
        );
50
        $client = $this->getAuthClient();
51
        $client->request('POST', $url, []);
52
        $response = $client->getResponse();
53
        $this->assertEquals(400, $response->getStatusCode());
54
        $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...
55
        //$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...
56
    }
57
58
59
    /**
60
     * @group lead
61
     * @group put
62
     * @group controller
63
     */
64
    public function testPutValide()
65
    {
66
		$this->loadFixtureFiles([
67
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
68
			'@StarkerxpLeadBundle/Tests/DataFixtures/LeadActionManager/DefaultLeadAction.yml',
69
		]);
70
        $manager = $this->getContainer()->get('starkerxp_lead.manager.leadaction');
71
        $listeLeads = $manager->getRepository()->findAll();
72
        $this->assertCount(1, $listeLeads);
73
        $LeadActionDepart = $manager->toArray($listeLeads[0], [/*'nom'*/]);// Exemple
74
        $data = [
75
            //'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...
76
        ];
77
		$url = $this->generateUrl(
78
            'starkerxp_lead.lead.put',
79
            [
80
				"id"    => $listeLeads[0]->getId(),
81
			]
82
        );
83
        $client = $this->getAuthClient();
84
        $client->request('PUT', $url, $data);
85
        $response = $client->getResponse();
86
        $this->assertEquals(204, $response->getStatusCode());
87
        $manager->clear();
88
        $LeadActions = $manager->findAll();
89
        $this->assertCount(1, $LeadActions);
90
        $LeadActionFinal = $manager->toArray($LeadActions[0], [/*'nom'*/]);// Exemple
91
        $this->assertNotEquals($LeadActionDepart, $LeadActionFinal);
92
        $this->assertEquals($data, $LeadActionFinal);
93
    }
94
95
    /**
96
     * @group lead
97
     * @group put
98
     * @group controller
99
     */
100
    public function testPutInvalide()
101
    {
102
		$this->loadFixtureFiles([
103
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
104
			'@StarkerxpLeadBundle/Tests/DataFixtures/LeadActionManager/DefaultLeadAction.yml',
105
		]);
106
        $manager = $this->getContainer()->get('starkerxp_lead.manager.leadaction');
107
        $listeLeads = $manager->getRepository()->findAll();
108
        $this->assertCount(1, $listeLeads);
109
		$url = $this->generateUrl(
110
            'starkerxp_lead.lead.put',
111
            [
112
				"id"    => $listeLeads[0]->getId(),
113
			]
114
        );
115
        $client = $this->getAuthClient();
116
        $client->request('PUT', $url, []);
117
        $response = $client->getResponse();
118
        $this->assertEquals(400, $response->getStatusCode());
119
        $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...
120
        //$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...
121
        
122
    }
123
124
    /**
125
     * @group lead
126
     * @group put
127
     * @group controller
128
     */
129 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...
130
    {
131
		$this->loadFixtureFiles([
132
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
133
		]);
134
        $data = [
135
            //'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...
136
        ];
137
		$url = $this->generateUrl(
138
            'starkerxp_lead.lead.put',
139
            [
140
				"id"    => 404,
141
			]
142
        );
143
        $client = $this->getAuthClient();
144
        $client->request('PUT', $url, $data);
145
        $response = $client->getResponse();
146
        $this->assertEquals(404, $response->getStatusCode());
147
        $body = json_decode($response->getContent(), true);
148
        $this->assertNotEmpty($body);
149
    }
150
151
152
    /**
153
     * @group lead
154
     * @group cget
155
     * @group controller
156
     */
157 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...
158
    {
159
		$this->loadFixtureFiles([
160
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
161
			'@StarkerxpLeadBundle/Tests/DataFixtures/LeadActionManager/LeadManager.yml',
162
		]);
163
		$url = $this->generateUrl(
164
            'starkerxp_lead.lead.cget',
165
            [
166
				
167
			]
168
        );
169
        $client = $this->getAuthClient();
170
        $client->request('GET', $url, []);
171
        $response = $client->getResponse();
172
        $this->assertEquals(200, $response->getStatusCode());
173
        $body = json_decode($response->getContent(), true);
174
        $this->assertCount(10, $body);
175
        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...
176
            //$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...
177
        }
178
    }
179
180
    /**
181
     * @group lead
182
     * @group cget
183
     * @group controller
184
     */
185 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...
186
    {
187
		$this->loadFixtureFiles([
188
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
189
		]);
190
		$url = $this->generateUrl(
191
            'starkerxp_lead.lead.cget',
192
            [
193
				
194
			]
195
        );
196
        $client = $this->getAuthClient();
197
        $client->request('GET', $url, []);
198
        $response = $client->getResponse();
199
        $this->assertEquals(200, $response->getStatusCode());
200
        $body = json_decode($response->getContent(), true);
201
        $this->assertCount(0, $body);
202
    }
203
204
    /**
205
     * @group lead
206
     * @group cget
207
     * @group controller
208
     */
209 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...
210
    {
211
		$this->loadFixtureFiles([
212
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
213
		]);
214
		$url = $this->generateUrl(
215
            'starkerxp_lead.lead.cget',
216
            [
217
				
218
			]
219
        );
220
        $client = $this->getAuthClient();
221
        $client->request('GET', $url, ["filter_erreur" => "+h"]);
222
        $response = $client->getResponse();
223
        $this->assertEquals(400, $response->getStatusCode());
224
    }
225
226
    /**
227
     * @group lead
228
     * @group get
229
     * @group controller
230
     */
231 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...
232
    {
233
		$this->loadFixtureFiles([
234
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
235
			'@StarkerxpLeadBundle/Tests/DataFixtures/LeadActionManager/LeadManager.yml',
236
		]);
237
        $manager = $this->getContainer()->get('starkerxp_lead.manager.leadaction');
238
        $listeLeads = $manager->getRepository()->findAll();
239
        $this->assertCount(10, $listeLeads);
240
		$url = $this->generateUrl(
241
            'starkerxp_lead.lead.get',
242
            [
243
				"id" => $listeLeads[0]->getId(),
244
			]
245
        );
246
        $client = $this->getAuthClient();
247
        $client->request('GET', $url, []);
248
        $response = $client->getResponse();
249
        $this->assertEquals(200, $response->getStatusCode());
250
        $body = json_decode($response->getContent(), true);
251
        $this->assertCount(5, $body);
252
        //$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...
253
    }
254
255
    /**
256
     * @group lead
257
     * @group get
258
     * @group controller
259
     */
260 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...
261
    {
262
		$this->loadFixtureFiles([
263
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
264
		]);
265
		$url = $this->generateUrl(
266
            'starkerxp_lead.lead.get',
267
            [
268
				"id" => 404,
269
			]
270
        );
271
        $client = $this->getAuthClient();
272
        $client->request('GET', $url, []);
273
        $response = $client->getResponse();
274
        $this->assertEquals(404, $response->getStatusCode());
275
        $body = json_decode($response->getContent(), true);
276
        $this->assertNotEmpty($body);
277
    }
278
279
    /**
280
     * @group lead
281
     * @group get
282
     * @group controller
283
     */
284
    public function testGetInvalide()
285
    {
286
		$this->loadFixtureFiles([
287
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
288
		]);
289
		$url = $this->generateUrl(
290
            'starkerxp_lead.lead.get',
291
            [
292
				"id" => 500,
293
			]
294
        );
295
        $client = $this->getAuthClient();
296
        $client->request('GET', $url, ["filter_erreur" => "+h"]);
297
        $response = $client->getResponse();
298
        $this->assertEquals(400, $response->getStatusCode());
299
    }
300
301
    /**
302
     * @group lead
303
     * @group delete
304
     * @group controller
305
     */
306 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...
307
    {
308
		$this->loadFixtureFiles([
309
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
310
			'@StarkerxpLeadBundle/Tests/DataFixtures/LeadActionManager/DefaultLeadAction.yml',
311
		]);
312
        $manager = $this->getContainer()->get('starkerxp_lead.manager.leadaction');
313
        $listeLeads = $manager->getRepository()->findAll();
314
        $this->assertCount(1, $listeLeads);
315
		$url = $this->generateUrl(
316
            'starkerxp_lead.lead.delete',
317
            [
318
				"id" => $listeLeads[0]->getId(),
319
			]
320
        );
321
        $client = $this->getAuthClient();
322
        $client->request('DELETE', $url);
323
        $response = $client->getResponse();
324
        $this->assertEquals(204, $response->getStatusCode());
325
        $manager->clear();
326
        $LeadActions = $manager->findAll();
327
        $this->assertCount(0, $LeadActions);
328
    }
329
330
    /**
331
     * @group lead
332
     * @group delete
333
     * @group controller
334
     */
335 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...
336
    {
337
		$this->loadFixtureFiles([
338
            '@StarkerxpUtilisateurBundle/Tests/DataFixtures/UtilisateurManager/DefaultUtilisateur.yml',
339
		]);
340
		$url = $this->generateUrl(
341
            'starkerxp_lead.lead.get',
342
            [
343
				"id" => 404,
344
			]
345
        );
346
        $client = $this->getAuthClient();
347
        $client->request('DELETE', $url, []);
348
        $response = $client->getResponse();
349
        $this->assertEquals(404, $response->getStatusCode());
350
        $body = json_decode($response->getContent(), true);
351
        $this->assertNotEmpty($body);
352
    }
353
}
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...
354