Passed
Push — master ( 433ac3...7aeedc )
by Adrien
13:53
created

AbstractAcl   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
dl 0
loc 44
ccs 0
cts 18
cp 0
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testRole() 0 27 1
A testEverythingIsTranslated() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Testing\Acl;
6
7
use Ecodev\Felix\Acl\Acl;
8
use PHPUnit\Framework\TestCase;
9
10
abstract class AbstractAcl extends TestCase
11
{
12
    abstract protected function createAcl(): Acl;
13
14
    abstract public function providerRole(): iterable;
15
16
    /**
17
     * @dataProvider providerRole
18
     */
19
    final public function testRole(string $role): void
20
    {
21
        $acl = $this->createAcl();
22
        $actual = $acl->show($role, false);
23
24
        $file = "tests/data/acl/$role.php";
25
        $logFile = "logs/$file";
26
27
        $dir = dirname($logFile);
28
        @mkdir($dir, 0o777, true);
29
        $serialized = ve($actual, true);
30
        file_put_contents(
31
            $logFile,
32
            <<<STRING
33
                <?php
34
35
                declare(strict_types=1);
36
37
                return $serialized;
38
39
                STRING
40
        );
41
42
        self::assertFileExists($file, 'Expected file must exist on disk, fix it with: cp ' . $logFile . ' ' . $file);
43
44
        $expected = require $file;
45
        self::assertTrue($expected === $actual, 'File content does not match, compare with: meld ' . $file . ' ' . $logFile);
46
    }
47
48
    final public function testEverythingIsTranslated(): void
49
    {
50
        $acl = $this->createAcl();
51
        $roles = $acl->getRoles();
52
        $config = $acl->show(reset($roles));
53
        self::assertIsArray($config);
54
    }
55
}
56