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

SameLevelModuleComparatorTest::dataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 72
Code Lines 48

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 48
nc 1
nop 0
dl 0
loc 72
rs 9.1344
c 1
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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