ConstantRemovedTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testDiffs() 0 13 1
A classesToBeTested() 0 19 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassBased;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\BackwardCompatibility\Change;
9
use Roave\BackwardCompatibility\DetectChanges\BCBreak\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
use function array_map;
15
use function iterator_to_array;
16
17
final class ConstantRemovedTest extends TestCase
18
{
19
    /**
20
     * @param string[] $expectedMessages
21
     *
22
     * @dataProvider classesToBeTested
23
     */
24
    public function testDiffs(
25
        ReflectionClass $fromClass,
26
        ReflectionClass $toClass,
27
        array $expectedMessages
28
    ) : void {
29
        $changes = (new ConstantRemoved())
30
            ->__invoke($fromClass, $toClass);
31
32
        self::assertSame(
33
            $expectedMessages,
34
            array_map(static function (Change $change) : string {
35
                return $change->__toString();
36
            }, iterator_to_array($changes))
37
        );
38
    }
39
40
    /**
41
     * @return array<string, array<int, ReflectionClass|array<int, string>>>
42
     *
43
     * @psalm-return array<string, array{0: ReflectionClass, 1: ReflectionClass, 2: list<string>}>
44
     */
45
    public function classesToBeTested() : array
46
    {
47
        $locator = (new BetterReflection())->astLocator();
48
49
        return [
50
            'RoaveTestAsset\\ClassWithConstantsBeingRemoved' => [
51
                (new ClassReflector(new SingleFileSourceLocator(
52
                    __DIR__ . '/../../../../asset/api/old/ClassWithConstantsBeingRemoved.php',
53
                    $locator
54
                )))->reflect('RoaveTestAsset\\ClassWithConstantsBeingRemoved'),
55
                (new ClassReflector(new SingleFileSourceLocator(
56
                    __DIR__ . '/../../../../asset/api/new/ClassWithConstantsBeingRemoved.php',
57
                    $locator
58
                )))->reflect('RoaveTestAsset\\ClassWithConstantsBeingRemoved'),
59
                [
60
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::removedPublicConstant was removed',
61
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::nameCaseChangePublicConstant was removed',
62
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::removedProtectedConstant was removed',
63
                    '[BC] REMOVED: Constant RoaveTestAsset\ClassWithConstantsBeingRemoved::nameCaseChangeProtectedConstant was removed',
64
                ],
65
            ],
66
        ];
67
    }
68
}
69