Completed
Push — master ( a80802...7141a9 )
by Serhii
13s queued 10s
created

EmployeesControllerTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 25
loc 75
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetEmployees() 0 4 1
A testGetEmployeesSlug() 0 6 1
A testGetEmployeesSlugRoles() 0 6 1
A testEmployeesResponseFields() 25 25 3
A getEntityFields() 0 16 1
A getListFields() 0 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 App\Tests\Functional\Controller;
4
5
class EmployeesControllerTest extends AbstractController
6
{
7
    public function testGetEmployees()
8
    {
9
        $this->restRequest('/api/employees');
10
    }
11
12
    public function testGetEmployeesSlug()
13
    {
14
        $slug = $this->getEm()->getRepository('App:Employee')->findOneBy([])->getSlug();
15
        $this->restRequest('/api/employees/'.$slug);
16
        $this->restRequest('/api/employees/nonexistent-slug', 'GET', 404);
17
    }
18
19
    public function testGetEmployeesSlugRoles()
20
    {
21
        $slug = $this->getEm()->getRepository('App:Employee')->findOneBy([])->getSlug();
22
        $this->restRequest('/api/employees/'.$slug.'/roles');
23
        $this->restRequest('/api/employees/nonexistent-slug/roles', 'GET', 404);
24
    }
25
26 View Code Duplication
    public function testEmployeesResponseFields()
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...
27
    {
28
        $this->restRequest('/api/employees');
29
        $response = json_decode($this->getSessionClient()->getResponse()->getContent(), true);
30
31
        $this->assertEquals(
32
            count($this->getListFields()),
33
            count(array_keys($response))
34
        );
35
36
        foreach ($this->getListFields() as $field) {
37
            $this->assertArrayHasKey($field, $response);
38
        }
39
40
        $firstEntity = array_shift($response['employees']);
41
42
        $this->assertEquals(
43
            count($this->getEntityFields()),
44
            count(array_keys($firstEntity))
45
        );
46
47
        foreach ($this->getEntityFields() as $field) {
48
            $this->assertArrayHasKey($field, $firstEntity);
49
        }
50
    }
51
52
    private function getEntityFields()
53
    {
54
        return array (
55
            'locale',
56
            'first_name',
57
            'last_name',
58
            'dob',
59
            'position',
60
            'biography',
61
            'gallery',
62
            'slug',
63
            'avatar',
64
            'created_at',
65
            'updated_at',
66
        );
67
    }
68
69
    private function getListFields()
70
    {
71
        return array (
72
            '_links',
73
            'page',
74
            'total_count',
75
            'employees',
76
            'count',
77
        );
78
    }
79
}
80