Passed
Pull Request — master (#50)
by Marco
02:46
created

MethodRemovedTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A classesToBeTested() 0 17 1
A testDiffs() 0 13 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\MethodRemoved;
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 MethodRemovedTest extends TestCase
18
{
19
    /**
20
     * @dataProvider classesToBeTested
21
     *
22
     * @param string[] $expectedMessages
23
     */
24
    public function testDiffs(
25
        ReflectionClass $fromClass,
26
        ReflectionClass $toClass,
27
        array $expectedMessages
28
    ) : void {
29
        $changes = (new MethodRemoved())
30
            ->__invoke($fromClass, $toClass);
31
32
        self::assertSame(
33
            $expectedMessages,
34
            array_map(function (Change $change) : string {
35
                return $change->__toString();
36
            }, iterator_to_array($changes))
37
        );
38
    }
39
40
    /** @return (string[]|ReflectionClass)[][] */
41
    public function classesToBeTested() : array
42
    {
43
        $locator = (new BetterReflection())->astLocator();
44
45
        return [
46
            'RoaveTestAsset\\ClassWithMethodsBeingRemoved' => [
47
                (new ClassReflector(new SingleFileSourceLocator(
48
                    __DIR__ . '/../../../../asset/api/old/ClassWithMethodsBeingRemoved.php',
49
                    $locator
50
                )))->reflect('RoaveTestAsset\\ClassWithMethodsBeingRemoved'),
51
                (new ClassReflector(new SingleFileSourceLocator(
52
                    __DIR__ . '/../../../../asset/api/new/ClassWithMethodsBeingRemoved.php',
53
                    $locator
54
                )))->reflect('RoaveTestAsset\\ClassWithMethodsBeingRemoved'),
55
                [
56
                    '[BC] REMOVED: Method RoaveTestAsset\ClassWithMethodsBeingRemoved#removedPublicMethod() was removed',
57
                    '[BC] REMOVED: Method RoaveTestAsset\ClassWithMethodsBeingRemoved#removedProtectedMethod() was removed',
58
                ],
59
            ],
60
        ];
61
    }
62
}
63