Completed
Pull Request — develop (#189)
by Serhii
02:23
created

EmployeesControllerTest::employeesGroupCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
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
    public static function employeesGroupCount(): array
27
    {
28
        return [
29
            ['actors', 37],
30
            ['art-core', 11],
31
            ['ballet', 8],
32
            ['administrative-accounting', 4],
33
            ['orchestra', 12],
34
            ['art-production', 15],
35
            ['deputies', 2],
36
            ['epoch', 4],
37
        ];
38
    }
39
40
    /**
41
     * @dataProvider employeesGroupCount
42
     */
43
    public function testGetEmployeesFilteredByGroup(string $group, int $count)
44
    {
45
        $this->restRequest('/api/employees?group='.$group);
46
        $response = json_decode($this->getSessionClient()->getResponse()->getContent(), true);
47
        $this->assertCount($count, $response['employees']);
48
    }
49
50
    public function testEmployeesResponseFields()
51
    {
52
        $this->restRequest('/api/employees');
53
        $response = json_decode($this->getSessionClient()->getResponse()->getContent(), true);
54
        $firstEntity = array_shift($response['employees']);
55
56
        $this->assertEquals(
57
            count($this->getEntityFields()),
58
            count(array_keys($firstEntity))
59
        );
60
61
        foreach ($this->getEntityFields() as $field) {
62
            $this->assertArrayHasKey($field, $firstEntity);
63
        }
64
    }
65
66
    private function getEntityFields(): array
67
    {
68
        return [
69
            'locale',
70
            'first_name',
71
            'last_name',
72
            'dob',
73
            'position',
74
            'biography',
75
            'gallery',
76
            'slug',
77
            'avatar',
78
            'created_at',
79
            'updated_at',
80
            'staff',
81
        ];
82
    }
83
}
84