Completed
Push — master ( a97f84...b5df1f )
by
unknown
11:58
created

Security/Acl/Permission/AdminPermissionMapTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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\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();
0 ignored issues
show
The property permissionMap does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
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->assertInternalType('array', $masks);
37
38
            foreach ($masks as $mask) {
39
                $this->assertInternalType('string', 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