1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\MethodBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Roave\ApiCompare\Change; |
9
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\MethodConcretenessChanged; |
10
|
|
|
use Roave\BetterReflection\BetterReflection; |
11
|
|
|
use Roave\BetterReflection\Reflection\ReflectionMethod; |
12
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
13
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
14
|
|
|
use function array_map; |
15
|
|
|
use function iterator_to_array; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\MethodConcretenessChanged |
19
|
|
|
*/ |
20
|
|
|
final class MethodConcretenessChangedTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @dataProvider propertiesToBeTested |
24
|
|
|
* |
25
|
|
|
* @param string[] $expectedMessages |
26
|
|
|
*/ |
27
|
|
|
public function testDiffs( |
28
|
|
|
ReflectionMethod $fromMethod, |
29
|
|
|
ReflectionMethod $toMethod, |
30
|
|
|
array $expectedMessages |
31
|
|
|
) : void { |
32
|
|
|
$changes = (new MethodConcretenessChanged()) |
33
|
|
|
->compare($fromMethod, $toMethod); |
34
|
|
|
|
35
|
|
|
self::assertSame( |
36
|
|
|
$expectedMessages, |
37
|
|
|
array_map(function (Change $change) : string { |
38
|
|
|
return $change->__toString(); |
39
|
|
|
}, iterator_to_array($changes)) |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** @return (string[]|ReflectionProperty)[][] */ |
44
|
|
|
public function propertiesToBeTested() : array |
45
|
|
|
{ |
46
|
|
|
$astLocator = (new BetterReflection())->astLocator(); |
47
|
|
|
|
48
|
|
|
$fromLocator = new StringSourceLocator( |
49
|
|
|
<<<'PHP' |
50
|
|
|
<?php |
51
|
|
|
|
52
|
|
|
abstract class TheClass { |
53
|
|
|
public function publicConcreteToAbstract() {} |
54
|
|
|
public abstract function publicAbstractToConcrete() {} |
55
|
|
|
public function publicConcreteToConcrete() {} |
56
|
|
|
public abstract function publicAbstractToAbstract() {} |
57
|
|
|
|
58
|
|
|
protected function protectedConcreteToAbstract() {} |
59
|
|
|
protected abstract function protectedAbstractToConcrete() {} |
60
|
|
|
protected function protectedConcreteToConcrete() {} |
61
|
|
|
protected abstract function protectedAbstractToAbstract() {} |
62
|
|
|
|
63
|
|
|
private function privateConcreteToAbstract() {} |
64
|
|
|
private abstract function privateAbstractToConcrete() {} |
65
|
|
|
private function privateConcreteToConcrete() {} |
66
|
|
|
private abstract function privateAbstractToAbstract() {} |
67
|
|
|
} |
68
|
|
|
PHP |
69
|
|
|
, |
70
|
|
|
$astLocator |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
$toLocator = new StringSourceLocator( |
74
|
|
|
<<<'PHP' |
75
|
|
|
<?php |
76
|
|
|
|
77
|
|
|
abstract class TheClass { |
78
|
|
|
public abstract function publicConcreteToAbstract() {} |
79
|
|
|
public function publicAbstractToConcrete() {} |
80
|
|
|
public function publicConcreteToConcrete() {} |
81
|
|
|
public abstract function publicAbstractToAbstract() {} |
82
|
|
|
|
83
|
|
|
protected abstract function protectedConcreteToAbstract() {} |
84
|
|
|
protected function protectedAbstractToConcrete() {} |
85
|
|
|
protected function protectedConcreteToConcrete() {} |
86
|
|
|
protected abstract function protectedAbstractToAbstract() {} |
87
|
|
|
|
88
|
|
|
private abstract function privateConcreteToAbstract() {} |
89
|
|
|
private function privateAbstractToConcrete() {} |
90
|
|
|
private function privateConcreteToConcrete() {} |
91
|
|
|
private abstract function privateAbstractToAbstract() {} |
92
|
|
|
} |
93
|
|
|
PHP |
94
|
|
|
, |
95
|
|
|
$astLocator |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$fromClassReflector = new ClassReflector($fromLocator); |
99
|
|
|
$toClassReflector = new ClassReflector($toLocator); |
100
|
|
|
$fromClass = $fromClassReflector->reflect('TheClass'); |
101
|
|
|
$toClass = $toClassReflector->reflect('TheClass'); |
102
|
|
|
|
103
|
|
|
$properties = [ |
104
|
|
|
'publicConcreteToAbstract' => [ |
105
|
|
|
'[BC] CHANGED: Method publicConcreteToAbstract() of class TheClass changed from concrete to abstract', |
106
|
|
|
], |
107
|
|
|
'publicAbstractToConcrete' => [], |
108
|
|
|
'publicConcreteToConcrete' => [], |
109
|
|
|
'publicAbstractToAbstract' => [], |
110
|
|
|
|
111
|
|
|
'protectedConcreteToAbstract' => [ |
112
|
|
|
'[BC] CHANGED: Method protectedConcreteToAbstract() of class TheClass changed from concrete to abstract', |
113
|
|
|
], |
114
|
|
|
'protectedAbstractToConcrete' => [], |
115
|
|
|
'protectedConcreteToConcrete' => [], |
116
|
|
|
'protectedAbstractToAbstract' => [], |
117
|
|
|
|
118
|
|
|
'privateConcreteToAbstract' => [ |
119
|
|
|
'[BC] CHANGED: Method privateConcreteToAbstract() of class TheClass changed from concrete to abstract', |
120
|
|
|
], |
121
|
|
|
'privateAbstractToConcrete' => [], |
122
|
|
|
'privateConcreteToConcrete' => [], |
123
|
|
|
'privateAbstractToAbstract' => [], |
124
|
|
|
]; |
125
|
|
|
|
126
|
|
|
return array_combine( |
127
|
|
|
array_keys($properties), |
128
|
|
|
array_map( |
129
|
|
|
function (string $methodName, array $errorMessages) use ($fromClass, $toClass) : array { |
130
|
|
|
return [ |
131
|
|
|
$fromClass->getMethod($methodName), |
132
|
|
|
$toClass->getMethod($methodName), |
133
|
|
|
$errorMessages, |
134
|
|
|
]; |
135
|
|
|
}, |
136
|
|
|
array_keys($properties), |
137
|
|
|
$properties |
138
|
|
|
) |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|