|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\ClassBased; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Roave\ApiCompare\Change; |
|
9
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\ClassBecameAbstract; |
|
10
|
|
|
use Roave\BetterReflection\BetterReflection; |
|
11
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClass; |
|
12
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
|
13
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
|
14
|
|
|
use function array_combine; |
|
15
|
|
|
use function array_keys; |
|
16
|
|
|
use function array_map; |
|
17
|
|
|
use function iterator_to_array; |
|
18
|
|
|
|
|
19
|
|
|
final class ClassBecameAbstractTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @dataProvider classesToBeTested |
|
23
|
|
|
* |
|
24
|
|
|
* @param string[] $expectedMessages |
|
25
|
|
|
*/ |
|
26
|
|
|
public function testDiffs( |
|
27
|
|
|
ReflectionClass $fromClass, |
|
28
|
|
|
ReflectionClass $toClass, |
|
29
|
|
|
array $expectedMessages |
|
30
|
|
|
) : void { |
|
31
|
|
|
$changes = (new ClassBecameAbstract()) |
|
32
|
|
|
->compare($fromClass, $toClass); |
|
33
|
|
|
|
|
34
|
|
|
self::assertSame( |
|
35
|
|
|
$expectedMessages, |
|
36
|
|
|
array_map(function (Change $change) : string { |
|
37
|
|
|
return $change->__toString(); |
|
38
|
|
|
}, iterator_to_array($changes)) |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** @return (string[]|ReflectionClass)[][] */ |
|
43
|
|
|
public function classesToBeTested() : array |
|
44
|
|
|
{ |
|
45
|
|
|
$locator = (new BetterReflection())->astLocator(); |
|
46
|
|
|
$fromReflector = new ClassReflector(new StringSourceLocator( |
|
47
|
|
|
<<<'PHP' |
|
48
|
|
|
<?php |
|
49
|
|
|
|
|
50
|
|
|
class ConcreteToAbstract {} |
|
51
|
|
|
abstract class AbstractToConcrete {} |
|
52
|
|
|
class ConcreteToConcrete {} |
|
53
|
|
|
abstract class AbstractToAbstract {} |
|
54
|
|
|
class ConcreteToInterface {} |
|
55
|
|
|
interface InterfaceToConcrete {} |
|
56
|
|
|
interface InterfaceToInterface {} |
|
57
|
|
|
interface InterfaceToAbstract {} |
|
58
|
|
|
abstract class AbstractToInterface {} |
|
59
|
|
|
PHP |
|
60
|
|
|
, |
|
61
|
|
|
$locator |
|
62
|
|
|
)); |
|
63
|
|
|
$toReflector = new ClassReflector(new StringSourceLocator( |
|
64
|
|
|
<<<'PHP' |
|
65
|
|
|
<?php |
|
66
|
|
|
|
|
67
|
|
|
abstract class ConcreteToAbstract {} |
|
68
|
|
|
class AbstractToConcrete {} |
|
69
|
|
|
class ConcreteToConcrete {} |
|
70
|
|
|
abstract class AbstractToAbstract {} |
|
71
|
|
|
interface ConcreteToInterface {} |
|
72
|
|
|
class InterfaceToConcrete {} |
|
73
|
|
|
interface InterfaceToInterface {} |
|
74
|
|
|
abstract class InterfaceToAbstract {} |
|
75
|
|
|
interface AbstractToInterface {} |
|
76
|
|
|
PHP |
|
77
|
|
|
, |
|
78
|
|
|
$locator |
|
79
|
|
|
)); |
|
80
|
|
|
|
|
81
|
|
|
$classes = [ |
|
82
|
|
|
'ConcreteToAbstract' => ['[BC] CHANGED: Class ConcreteToAbstract became abstract'], |
|
83
|
|
|
'AbstractToConcrete' => [], |
|
84
|
|
|
'ConcreteToConcrete' => [], |
|
85
|
|
|
'AbstractToAbstract' => [], |
|
86
|
|
|
'ConcreteToInterface' => [], |
|
87
|
|
|
'InterfaceToConcrete' => [], |
|
88
|
|
|
'InterfaceToInterface' => [], |
|
89
|
|
|
'InterfaceToAbstract' => [], |
|
90
|
|
|
'AbstractToInterface' => [], |
|
91
|
|
|
]; |
|
92
|
|
|
|
|
93
|
|
|
return array_combine( |
|
94
|
|
|
array_keys($classes), |
|
95
|
|
|
array_map( |
|
96
|
|
|
function (string $className, array $errors) use ($fromReflector, $toReflector) : array { |
|
97
|
|
|
return [ |
|
98
|
|
|
$fromReflector->reflect($className), |
|
99
|
|
|
$toReflector->reflect($className), |
|
100
|
|
|
$errors, |
|
101
|
|
|
]; |
|
102
|
|
|
}, |
|
103
|
|
|
array_keys($classes), |
|
104
|
|
|
$classes |
|
105
|
|
|
) |
|
106
|
|
|
); |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|