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

EmployeesControllerTest::getListFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
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