Completed
Push — master ( e4a474...3a3d8d )
by Guillaume
02:43
created

LeadControllerTest::testPutSansResultat()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 21
Ratio 87.5 %

Importance

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