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

ConstantRemovedTest::classesToBeTested()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 15
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\ConstantRemoved;
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 ConstantRemovedTest 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 ConstantRemoved())
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\\ClassWithConstantsBeingRemoved' => [
45
                (new ClassReflector(new SingleFileSourceLocator(
46
                    __DIR__ . '/../../../../asset/api/old/ClassWithConstantsBeingRemoved.php',
47
                    $locator
48
                )))->reflect('RoaveTestAsset\\ClassWithConstantsBeingRemoved'),
49
                (new ClassReflector(new SingleFileSourceLocator(
50
                    __DIR__ . '/../../../../asset/api/new/ClassWithConstantsBeingRemoved.php',
51
                    $locator
52
                )))->reflect('RoaveTestAsset\\ClassWithConstantsBeingRemoved'),
53
                [
54
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::removedPublicConstant was removed',
55
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::nameCaseChangePublicConstant was removed',
56
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::removedProtectedConstant was removed',
57
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::nameCaseChangeProtectedConstant was removed',
58
                ],
59
            ],
60
        ];
61
    }
62
}
63