Completed
Push — master ( c5d644...a435b5 )
by Guillaume
02:45
created

LeadControllerTest::testGetValideAvecResultats()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

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