Test Failed
Push — feature/add-phpstan-rules ( 26ac25 )
by Dave
10:33
created

SameLevelModuleComparatorTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 53
dl 0
loc 96
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dataProvider() 0 72 1
A test_module_comparator() 0 4 1
A test_module_comparator_without_trailing_slash() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaPhpstan\Tests;
6
7
use GacelaPhpstan\Rules\SameLevelModuleComparator;
8
use PHPUnit\Framework\TestCase;
9
10
class SameLevelModuleComparatorTest extends TestCase
11
{
12
    /**
13
     * @return iterable<int,array{?string,?string,bool}>
14
     */
15
    public function dataProvider(): iterable
16
    {
17
        yield [
18
            null,
19
            null,
20
            true,
21
        ];
22
23
        yield [
24
            null,
25
            'Foo',
26
            false,
27
        ];
28
29
        yield [
30
            'Bar',
31
            null,
32
            false,
33
        ];
34
35
        yield [
36
            'Foo/bar',
37
            'Foo/bar',
38
            true,
39
        ];
40
41
        yield [
42
            'Foo/baz',
43
            'Foo/bar',
44
            false,
45
        ];
46
47
        yield [
48
            'Foo/bar',
49
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Domain',
50
            false,
51
        ];
52
53
        yield [
54
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Domain',
55
            'Foo/bar',
56
            false,
57
        ];
58
59
        yield [
60
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Infrastructure',
61
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Domain',
62
            true,
63
        ];
64
65
        yield [
66
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Infrastructure\Foo',
67
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA',
68
            true,
69
        ];
70
71
        yield [
72
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA',
73
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Infrastructure',
74
            true,
75
        ];
76
77
        yield [
78
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Infrastructure',
79
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleB\Infrastructure',
80
            false,
81
        ];
82
83
        yield [
84
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\Infrastructure\Person',
85
            'GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\ModuleA\SomeClass',
86
            true,
87
        ];
88
    }
89
90
    /**
91
     * @dataProvider dataProvider
92
     */
93
    public function test_module_comparator(?string $namespaceA, ?string $namespaceB, bool $expected): void
94
    {
95
        $moduleComparator = new SameLevelModuleComparator('GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures\\');
96
        $this->assertSame($expected, $moduleComparator->isSameModule($namespaceA, $namespaceB));
97
    }
98
99
    /**
100
     * @dataProvider dataProvider
101
     */
102
    public function test_module_comparator_without_trailing_slash(?string $namespaceA, ?string $namespaceB, bool $expected): void
103
    {
104
        $moduleComparator = new SameLevelModuleComparator('GacelaPhpstan\Tests\EnforceModuleBoundariesForMethodCallRule\Fixtures');
105
        $this->assertSame($expected, $moduleComparator->isSameModule($namespaceA, $namespaceB));
106
    }
107
}
108