BeersControllerTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 19.61 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testPost() 0 13 1
A testGet() 0 6 1
A testPatch() 0 14 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\FoyerBundle\Controller;
4
5
use Tests\KI\CoreBundle\WebTestCase;
6
7
class BeersControllerTest extends WebTestCase
8
{
9
    // On crée une ressource sur laquelle seront effectués les tests.
10
    // Ne pas oublier de supprimer à la fin avec le test DELETE.
11
    public function testPost()
12
    {
13
        $this->client->request(
14
            'POST', '/beers', [
15
                'name' => 'Test Kro',
16
                'price' => 1,
17
                'alcohol' => 1,
18
                'volume' => 1
19
            ]
20
        );
21
        $response = $this->client->getResponse();
22
        $this->assertJsonResponse($response, 201);
23
    }
24
25
    public function testGet()
26
    {
27
        $this->client->request('GET', '/beers');
28
        $response = $this->client->getResponse();
29
        $this->assertJsonResponse($response, 200);
30
    }
31
32
    public function testPatch()
33
    {
34
        $this->client->request('PATCH', '/beers/test-kro', ['alcohol' => 100]);
35
        $response = $this->client->getResponse();
36
        $this->assertJsonResponse($response, 204);
37
38
        $this->client->request('PATCH', '/beers/test-kro', ['alcohol' => 'blah']);
39
        $response = $this->client->getResponse();
40
        $this->assertJsonResponse($response, 400);
41
42
        $this->client->request('PATCH', '/beers/test-ksdqsdqsdsdqsdsdqsro', ['alcohol' => 'blah']);
43
        $response = $this->client->getResponse();
44
        $this->assertJsonResponse($response, 404);
45
    }
46
47 View Code Duplication
    public function testDelete()
48
    {
49
        $this->client->request('DELETE', '/beers/test-kro');
50
        $response = $this->client->getResponse();
51
        $this->assertJsonResponse($response, 204);
52
53
        $this->client->request('DELETE', '/beers/test-kro');
54
        $response = $this->client->getResponse();
55
        $this->assertJsonResponse($response, 404);
56
    }
57
}
58