Completed
Push — master ( a16ed8...b80d48 )
by Guillaume
07:23
created

testGetValideSansResultat()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

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