SecurityTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 78
Duplicated Lines 47.44 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFirewall() 11 11 1
A testClubMembership() 0 34 1
A testRoleAdmissible() 14 14 1
A testRoleExterieur() 12 12 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
namespace Tests\KI\PublicationBundle;
3
4
use Tests\KI\CoreBundle\WebTestCase;
5
6
class SecurityTest extends WebTestCase
7
{
8
    // Vérifie que les routes non firewallées sont utilisables
9 View Code Duplication
    public function testFirewall()
10
    {
11
        $this->client = static::createClient();
12
        $routes = [
13
            [401, 'GET', '/newsitems'],
14
            [404, 'GET', '/courses/mecanique-des-structures/exercices/test/download'],
15
            [200, 'GET', '/users/VpqtuEGC/calendar'],
16
            [401, 'POST', '/newsitems/le-beton-c-est-bon/comments'],
17
        ];
18
        $this->checkRoutes($routes);
19
    }
20
21
    public function testClubMembership()
22
    {
23
        // On se présente comme un trouffion de base
24
        $this->connect('donat-bb', 'password');
25
26
        // Maintenant on teste quelques trucs
27
        $this->client->request('POST', '/newsitems/le-beton-c-est-bon/comments');
28
        $response = $this->client->getResponse();
29
        $this->assertJsonResponse($response, 400);
30
31
        $this->client->request('POST', '/newsitems', ['name' => 'La Porte', 'text' => 'C\'est comme perdre']);
32
        $response = $this->client->getResponse();
33
        $this->assertJsonResponse($response, 201);
34
35
        $this->client->request('DELETE', '/newsitems/la-porte');
36
        $response = $this->client->getResponse();
37
        $this->assertJsonResponse($response, 204);
38
39
        $this->client->request('POST', '/newsitems', ['name' => 'La Porte', 'text' => 'C\'est comme perdre', 'authorClub' => 'bde']);
40
        $response = $this->client->getResponse();
41
        $this->assertJsonResponse($response, 403);
42
43
        $this->client->request('DELETE', '/newsitems/le-jeu');
44
        $response = $this->client->getResponse();
45
        $this->assertJsonResponse($response, 403);
46
47
        $this->client->request('POST', '/newsitems', ['name' => 'Manger', 'text' => 'C\'est comme perdre', 'authorClub' => 'bda']);
48
        $response = $this->client->getResponse();
49
        $this->assertJsonResponse($response, 201);
50
51
        $this->client->request('DELETE', '/newsitems/manger');
52
        $response = $this->client->getResponse();
53
        $this->assertJsonResponse($response, 204);
54
    }
55
56 View Code Duplication
    public function testRoleAdmissible()
57
    {
58
        // On se présente comme un admissible
59
        $this->connect('admissibles', 'password');
60
        $routes = [
61
            [200, 'GET', '/newsitems'],
62
            [200, 'GET', '/courses'],
63
            [403, 'POST', '/newsitems'],
64
            [403, 'POST', '/events'],
65
            [403, 'PATCH', '/events/don-giovanni'],
66
            [403, 'PATCH', '/newsitems/pulls'],
67
        ];
68
        $this->checkRoutes($routes);
69
    }
70
71 View Code Duplication
    public function testRoleExterieur()
72
    {
73
        // On se présente comme un extérieur de l'administration
74
        $this->connect('gcc', 'password');
75
        $routes = [
76
            [200, 'GET', '/newsitems'],
77
            [403, 'GET', '/courses'],
78
            [403, 'POST', '/newsitems/le-beton-c-est-bon/comments'],
79
            [200, 'GET', '/newsitems/le-beton-c-est-bon/comments']
80
        ];
81
        $this->checkRoutes($routes);
82
    }
83
}
84