OneTest   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetName() 0 14 1
A testAssert() 0 16 2
A providerAssert() 0 10 1
A setUp() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace EcodevTests\Felix\Acl\Assertion;
6
7
use Ecodev\Felix\Acl\Acl;
8
use Ecodev\Felix\Acl\Assertion\NamedAssertion;
9
use Ecodev\Felix\Acl\Assertion\One;
10
use EcodevTests\Felix\Traits\TestWithContainer;
11
use PHPUnit\Framework\TestCase;
12
13
class OneTest extends TestCase
14
{
15
    use TestWithContainer;
16
17
    protected function setUp(): void
18
    {
19
        $this->createDefaultFelixContainer();
20
    }
21
22
    /**
23
     * @dataProvider providerAssert
24
     */
25
    public function testAssert(array $input, bool $expected): void
26
    {
27
        $assertions = [];
28
        foreach ($input as $value) {
29
            $internalAssertion = $this->createMock(NamedAssertion::class);
30
            $internalAssertion->expects(self::atMost(1))
31
                ->method('assert')
32
                ->willReturn($value);
33
34
            $assertions[] = $internalAssertion;
35
        }
36
37
        $assertion = new One(...$assertions);
38
39
        $acl = $this->createMock(Acl::class);
40
        self::assertSame($expected, $assertion->assert($acl));
41
    }
42
43
    public static function providerAssert(): iterable
44
    {
45
        return [
46
            [[], false],
47
            [[true], true],
48
            [[true, true], true],
49
            [[true, false], true],
50
            [[false, true], true],
51
            [[false, false], false],
52
            [[false], false],
53
        ];
54
    }
55
56
    public function testGetName(): void
57
    {
58
        $assert1 = $this->createMock(NamedAssertion::class);
59
        $assert1->expects(self::once())
60
            ->method('getName')
61
            ->willReturn('assert1');
62
63
        $assert2 = $this->createMock(NamedAssertion::class);
64
        $assert2->expects(self::once())
65
            ->method('getName')
66
            ->willReturn('assert2');
67
68
        $assert = new One($assert1, $assert2);
69
        self::assertSame('assert1, ou assert2', $assert->getName());
70
    }
71
}
72