Completed
Pull Request — master (#33)
by Marco
01:51
created

ConstantVisibilityReducedTest::classesToBeTested()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 14
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\ClassBased;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\ApiCompare\Change;
9
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\ConstantVisibilityReduced;
10
use Roave\BetterReflection\BetterReflection;
11
use Roave\BetterReflection\Reflection\ReflectionClass;
12
use Roave\BetterReflection\Reflector\ClassReflector;
13
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
14
15
final class ConstantVisibilityReducedTest extends TestCase
16
{
17
    /**
18
     * @dataProvider classesToBeTested
19
     *
20
     * @param string[] $expectedMessages
21
     */
22
    public function testDiffs(
23
        ReflectionClass $fromClass,
24
        ReflectionClass $toClass,
25
        array $expectedMessages
26
    ) : void {
27
        $changes = (new ConstantVisibilityReduced())
28
            ->compare($fromClass, $toClass);
29
30
        self::assertSame(
31
            $expectedMessages,
32
            array_map(function (Change $change) : string {
33
                return $change->__toString();
34
            }, iterator_to_array($changes))
35
        );
36
    }
37
38
    /** @return (string[]|ReflectionClass)[][] */
39
    public function classesToBeTested() : array
40
    {
41
        $locator = (new BetterReflection())->astLocator();
42
43
        return [
44
            'RoaveTestAsset\\ClassWithConstantVisibilitiesBeingChanged' => [
45
                (new ClassReflector(new SingleFileSourceLocator(
46
                    __DIR__ . '/../../../../asset/api/old/ClassWithConstantVisibilitiesBeingChanged.php',
47
                    $locator
48
                )))->reflect('RoaveTestAsset\\ClassWithConstantVisibilitiesBeingChanged'),
49
                (new ClassReflector(new SingleFileSourceLocator(
50
                    __DIR__ . '/../../../../asset/api/new/ClassWithConstantVisibilitiesBeingChanged.php',
51
                    $locator
52
                )))->reflect('RoaveTestAsset\\ClassWithConstantVisibilitiesBeingChanged'),
53
                [
54
                    '[BC] CHANGED: Constant RoaveTestAsset\ClassWithConstantVisibilitiesBeingChanged::publicReducedToProtected changed visibility from public to protected',
55
                    '[BC] CHANGED: Constant RoaveTestAsset\ClassWithConstantVisibilitiesBeingChanged::publicReducedToPrivate changed visibility from public to private',
56
                    '[BC] CHANGED: Constant RoaveTestAsset\ClassWithConstantVisibilitiesBeingChanged::protectedReducedToPrivate changed visibility from protected to private',
57
                ],
58
            ],
59
        ];
60
    }
61
}
62