Completed
Pull Request — master (#191)
by Serhii
02:32
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
    public function testEmployeesResponseFields()
27
    {
28
        $this->restRequest('/api/employees');
29
        $response = json_decode($this->getSessionClient()->getResponse()->getContent(), true);
30
        $firstEntity = array_shift($response['employees']);
31
32
        $this->assertEquals(
33
            count($this->getEntityFields()),
34
            count(array_keys($firstEntity))
35
        );
36
37
        foreach ($this->getEntityFields() as $field) {
38
            $this->assertArrayHasKey($field, $firstEntity);
39
        }
40
    }
41
42
    private function getEntityFields(): array
43
    {
44
        return [
45
            'locale',
46
            'first_name',
47
            'last_name',
48
            'dob',
49
            'position',
50
            'biography',
51
            'gallery',
52
            'slug',
53
            'avatar',
54
            'created_at',
55
            'updated_at',
56
            'staff',
57
        ];
58
    }
59
}
60