Passed
Pull Request — master (#1)
by James
02:50
created

testRenamingParametersDoesNotCauseBCBreak()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace RoaveTest\ApiCompare;
5
6
use Roave\ApiCompare\Comparator;
7
use PHPUnit\Framework\TestCase;
8
use Roave\ApiCompare\Factory\DirectoryReflectorFactory;
9
use Roave\BetterReflection\BetterReflection;
10
use Roave\BetterReflection\Reflector\ClassReflector;
11
use Roave\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
12
use Roave\BetterReflection\SourceLocator\Type\EvaledCodeSourceLocator;
13
use Roave\BetterReflection\SourceLocator\Type\PhpInternalSourceLocator;
14
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
15
16
/**
17
 * @covers \Roave\ApiCompare\Comparator
18
 */
19
final class ComparatorTest extends TestCase
20
{
21
    public function testCompare(): void
22
    {
23
        $reflectorFactory = new DirectoryReflectorFactory();
24
        self::assertEquals(
25
            [
26
                '[BC] Parameter something (position 0) in Thing::__construct has been deleted',
27
                '[BC] Method methodGone in class Thing has been deleted',
28
                '[BC] Class ClassGone has been deleted',
29
            ],
30
            (new Comparator())->compare(
31
                $reflectorFactory->__invoke(__DIR__ . '/../asset/api/old'),
32
                $reflectorFactory->__invoke(__DIR__ . '/../asset/api/new')
33
            )
34
        );
35
    }
36
37
    public function testRenamingParametersDoesNotCauseBCBreak()
38
    {
39
        $reflectorFactory = function (string $sourceCode): ClassReflector {
40
            $astLocator = (new BetterReflection())->astLocator();
41
            return new ClassReflector(
42
                new AggregateSourceLocator([
43
                    new PhpInternalSourceLocator($astLocator),
44
                    new EvaledCodeSourceLocator($astLocator),
45
                    new StringSourceLocator($sourceCode, $astLocator),
46
                ])
47
            );
48
        };
49
50
        self::assertEquals(
51
            [],
52
            (new Comparator())->compare(
53
                $reflectorFactory('<?php class A { function foo(int $a, string $b) {} }'),
54
                $reflectorFactory('<?php class A { function foo(int $b, string $a) {} }')
55
            )
56
        );
57
    }
58
}
59