PontlyvalentsControllerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 67.69 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 44
loc 65
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testPost() 10 10 1
A testGet() 0 14 1
A testPatch() 24 24 1
A testDelete() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Tests\KI\UserBundle\Controller;
4
5
use Tests\KI\CoreBundle\WebTestCase;
6
7
class PontlyvalentsControllerTest extends WebTestCase
8
{
9
    // On crée une ressource sur laquelle seront effectués les tests. Ne pas oublier de supprimer à la fin avec le test DELETE.
10 View Code Duplication
    public function testPost()
11
    {
12
        $this->client->request(
13
            'POST', '/users/taquet-c/pontlyvalent', [
14
                'text' => 'Meilleure successeur possible <3'
15
            ]
16
        );
17
        $response = $this->client->getResponse();
18
        $this->assertJsonResponse($response, 201);
19
    }
20
21
    public function testGet()
22
    {
23
        $this->client->request('GET', '/users/pontlyvalent');
24
        $response = $this->client->getResponse();
25
        $this->assertJsonResponse($response, 200);
26
27
        $this->client->request('GET', '/users/taquet-c/pontlyvalent');
28
        $response = $this->client->getResponse();
29
        $this->assertJsonResponse($response, 200);
30
31
        $this->client->request('GET', '/users/taquet-c/sjoajsiohaysahais-asbsksaba7');
32
        $response = $this->client->getResponse();
33
        $this->assertJsonResponse($response, 404);
34
    }
35
36 View Code Duplication
    public function testPatch()
37
    {
38
        $this->client->request(
39
            'POST', '/users/taquet-c/pontlyvalent', [
40
            'text' => 'Aime les câlins <3'
41
            ]
42
        );
43
        $response = $this->client->getResponse();
44
        $this->assertJsonResponse($response, 201);
45
46
        $this->client->request(
47
            'POST', '/users/taquet-c/pontlyvalent', ['text' => '']
48
        );
49
        $response = $this->client->getResponse();
50
        $this->assertJsonResponse($response, 400);
51
52
        $this->client->request('POST', '/users/taquet-c/sjoajsiosbsksaba7', ['name' => 'miam', 'mail' => '[email protected]']);
53
        $response = $this->client->getResponse();
54
        $this->assertJsonResponse($response, 404);
55
56
        $this->client->request('POST', '/users/taquet-c/pontlyvalent', ['name' => 'miam', 'mail' => '[email protected]']);
57
        $response = $this->client->getResponse();
58
        $this->assertJsonResponse($response, 400);
59
    }
60
61 View Code Duplication
    public function testDelete()
62
    {
63
        $this->client->request('DELETE', '/users/taquet-c/pontlyvalent');
64
        $response = $this->client->getResponse();
65
        $this->assertJsonResponse($response, 204);
66
67
        $this->client->request('DELETE', '/users/taquet-c/pontlyvalent');
68
        $response = $this->client->getResponse();
69
        $this->assertJsonResponse($response, 404);
70
    }
71
}
72