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