Completed
Push — master ( a435b5...54b9b0 )
by Guillaume
14:56
created

LeadControllerTest::testPutInvalide()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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