|
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 testRenamingParametersDoesNotCauseBcBreak(): void |
|
51
|
|
|
{ |
|
52
|
|
|
self::assertEqualsIgnoringOrder( |
|
53
|
|
|
[], |
|
54
|
|
|
(new Comparator())->compare( |
|
55
|
|
|
self::$stringReflectorFactory->__invoke('<?php class A { function foo(int $a, string $b) {} }'), |
|
|
|
|
|
|
56
|
|
|
self::$stringReflectorFactory->__invoke('<?php class A { function foo(int $b, string $a) {} }') |
|
57
|
|
|
) |
|
58
|
|
|
); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
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.