Completed
Push — master ( c7f0ae...412313 )
by James
9s
created

ComparatorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 55
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCompare() 0 12 1
A setUpBeforeClass() 0 3 1
A assertEqualsIgnoringOrder() 0 3 1
A testRenamingParametersDoesNotCauseBcBreak() 0 7 1
A testRemovingAPrivateMethodDoesNotCauseBreak() 0 7 1
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
10
/**
11
 * @covers \Roave\ApiCompare\Comparator
12
 */
13
final class ComparatorTest extends TestCase
14
{
15
    /**
16
     * @var StringReflectorFactory|null
17
     */
18
    private static $stringReflectorFactory;
19
20
    public static function setUpBeforeClass()
21
    {
22
        self::$stringReflectorFactory = new StringReflectorFactory();
23
    }
24
25
    /**
26
     * @param mixed $expected
27
     * @param mixed $actual
28
     */
29
    private static function assertEqualsIgnoringOrder($expected, $actual): void
30
    {
31
        self::assertEquals($expected, $actual, '', 0.0, 10, true);
32
    }
33
34
    public function testCompare(): void
35
    {
36
        $reflectorFactory = new DirectoryReflectorFactory();
37
        self::assertEqualsIgnoringOrder(
38
            [
39
                '[BC] Parameter something (position 0) in Thing::__construct has been deleted',
40
                '[BC] Method methodGone in class Thing has been deleted',
41
                '[BC] Class ClassGone has been deleted',
42
            ],
43
            (new Comparator())->compare(
44
                $reflectorFactory->__invoke(__DIR__ . '/../asset/api/old'),
45
                $reflectorFactory->__invoke(__DIR__ . '/../asset/api/new')
46
            )
47
        );
48
    }
49
50
    public function testRemovingAPrivateMethodDoesNotCauseBreak(): void
51
    {
52
        self::assertEqualsIgnoringOrder(
53
            [],
54
            (new Comparator())->compare(
55
                self::$stringReflectorFactory->__invoke('<?php class A { private function foo() {} }'),
0 ignored issues
show
Bug introduced by
The method __invoke() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
                self::$stringReflectorFactory->/** @scrutinizer ignore-call */ 
56
                                               __invoke('<?php class A { private function foo() {} }'),

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
56
                self::$stringReflectorFactory->__invoke('<?php class A { }')
57
            )
58
        );
59
    }
60
61
    public function testRenamingParametersDoesNotCauseBcBreak(): void
62
    {
63
        self::assertEqualsIgnoringOrder(
64
            [],
65
            (new Comparator())->compare(
66
                self::$stringReflectorFactory->__invoke('<?php class A { function foo(int $a, string $b) {} }'),
67
                self::$stringReflectorFactory->__invoke('<?php class A { function foo(int $b, string $a) {} }')
68
            )
69
        );
70
    }
71
}
72