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

AbstractAcl::testEverythingIsTranslated()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
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