Completed
Push — 3.x ( f37b5a...b37d45 )
by Christian
26:43
created

AdminPermissionMapTest   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testGetMaskReturnsAnArrayOfMasks() 0 16 3
A testGetMaskReturnsNullIfPermissionIsNotSupported() 0 7 1
A permissionProvider() 0 13 2
A testContainsReturnsABoolean() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Tests\Security\Acl\Permission;
15
16
use PHPUnit\Framework\TestCase;
17
use Sonata\AdminBundle\Security\Acl\Permission\AdminPermissionMap;
18
use Sonata\AdminBundle\Security\Acl\Permission\MaskBuilder;
19
20
class AdminPermissionMapTest extends TestCase
21
{
22
    protected function setUp(): void
23
    {
24
        $this->permissionMap = new AdminPermissionMap();
25
    }
26
27
    public function testGetMaskReturnsAnArrayOfMasks(): void
28
    {
29
        $reflection = new \ReflectionClass(AdminPermissionMap::class);
30
        foreach ($reflection->getConstants() as $permission) {
31
            $masks = $this->permissionMap->getMasks(
32
                $permission,
33
                new \stdClass()
34
            );
35
36
            $this->assertIsArray($masks);
37
38
            foreach ($masks as $mask) {
39
                $this->assertIsString(MaskBuilder::getCode($mask));
40
            }
41
        }
42
    }
43
44
    public function testGetMaskReturnsNullIfPermissionIsNotSupported(): void
45
    {
46
        $this->assertNull($this->permissionMap->getMasks(
47
            'unknown permission',
48
            new \stdClass()
49
        ));
50
    }
51
52
    public function permissionProvider()
53
    {
54
        $dataSet = [];
55
        $reflection = new \ReflectionClass(AdminPermissionMap::class);
56
57
        foreach ($reflection->getConstants() as $permission) {
58
            $dataSet[$permission] = [true, $permission];
59
        }
60
61
        return $dataSet + [
62
            'unknown permission' => [false, 'unknown permission'],
63
        ];
64
    }
65
66
    /**
67
     * @dataProvider permissionProvider
68
     */
69
    public function testContainsReturnsABoolean($expectedResult, $permission): void
70
    {
71
        $this->assertSame($expectedResult, $this->permissionMap->contains($permission));
72
    }
73
}
74