1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\InterfaceBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Roave\ApiCompare\Change; |
9
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\InterfaceBased\InterfaceBecameClass; |
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 InterfaceBecameClassTest 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 InterfaceBecameClass()) |
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
|
|
|
interface InterfaceToTrait {} |
60
|
|
|
trait TraitToInterface {} |
61
|
|
|
trait TraitToTrait {} |
62
|
|
|
PHP |
63
|
|
|
, |
64
|
|
|
$locator |
65
|
|
|
)); |
66
|
|
|
$toReflector = new ClassReflector(new StringSourceLocator( |
67
|
|
|
<<<'PHP' |
68
|
|
|
<?php |
69
|
|
|
|
70
|
|
|
abstract class ConcreteToAbstract {} |
71
|
|
|
class AbstractToConcrete {} |
72
|
|
|
class ConcreteToConcrete {} |
73
|
|
|
abstract class AbstractToAbstract {} |
74
|
|
|
interface ConcreteToInterface {} |
75
|
|
|
class InterfaceToConcrete {} |
76
|
|
|
interface InterfaceToInterface {} |
77
|
|
|
abstract class InterfaceToAbstract {} |
78
|
|
|
interface AbstractToInterface {} |
79
|
|
|
trait InterfaceToTrait {} |
80
|
|
|
interface TraitToInterface {} |
81
|
|
|
trait TraitToTrait {} |
82
|
|
|
PHP |
83
|
|
|
, |
84
|
|
|
$locator |
85
|
|
|
)); |
86
|
|
|
|
87
|
|
|
$classes = [ |
88
|
|
|
'ConcreteToAbstract' => [], |
89
|
|
|
'AbstractToConcrete' => [], |
90
|
|
|
'ConcreteToConcrete' => [], |
91
|
|
|
'AbstractToAbstract' => [], |
92
|
|
|
'ConcreteToInterface' => [], |
93
|
|
|
'InterfaceToConcrete' => ['[BC] CHANGED: Interface InterfaceToConcrete became a class'], |
94
|
|
|
'InterfaceToInterface' => [], |
95
|
|
|
'InterfaceToAbstract' => ['[BC] CHANGED: Interface InterfaceToAbstract became a class'], |
96
|
|
|
'AbstractToInterface' => [], |
97
|
|
|
'InterfaceToTrait' => [], |
98
|
|
|
'TraitToInterface' => [], |
99
|
|
|
'TraitToTrait' => [], |
100
|
|
|
]; |
101
|
|
|
|
102
|
|
|
return array_combine( |
103
|
|
|
array_keys($classes), |
104
|
|
|
array_map( |
105
|
|
|
function (string $className, array $errors) use ($fromReflector, $toReflector) : array { |
106
|
|
|
return [ |
107
|
|
|
$fromReflector->reflect($className), |
108
|
|
|
$toReflector->reflect($className), |
109
|
|
|
$errors, |
110
|
|
|
]; |
111
|
|
|
}, |
112
|
|
|
array_keys($classes), |
113
|
|
|
$classes |
114
|
|
|
) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|