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\MethodVisibilityReduced; |
10
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\PropertyVisibilityReduced; |
11
|
|
|
use Roave\BetterReflection\BetterReflection; |
12
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClass; |
13
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
14
|
|
|
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator; |
15
|
|
|
|
16
|
|
|
final class MethodVisibilityReducedTest extends TestCase |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @dataProvider classesToBeTested |
20
|
|
|
* |
21
|
|
|
* @param string[] $expectedMessages |
22
|
|
|
*/ |
23
|
|
|
public function testDiffs( |
24
|
|
|
ReflectionClass $fromClass, |
25
|
|
|
ReflectionClass $toClass, |
26
|
|
|
array $expectedMessages |
27
|
|
|
) : void { |
28
|
|
|
$changes = (new MethodVisibilityReduced()) |
29
|
|
|
->compare($fromClass, $toClass); |
30
|
|
|
|
31
|
|
|
self::assertSame( |
32
|
|
|
$expectedMessages, |
33
|
|
|
array_map(function (Change $change) : string { |
34
|
|
|
return $change->__toString(); |
35
|
|
|
}, iterator_to_array($changes)) |
36
|
|
|
); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** @return (string[]|ReflectionClass)[][] */ |
40
|
|
|
public function classesToBeTested() : array |
41
|
|
|
{ |
42
|
|
|
$locator = (new BetterReflection())->astLocator(); |
43
|
|
|
|
44
|
|
|
return [ |
45
|
|
|
'RoaveTestAsset\\ClassWithPropertyVisibilitiesBeingChanged' => [ |
46
|
|
|
(new ClassReflector(new SingleFileSourceLocator( |
47
|
|
|
__DIR__ . '/../../../../asset/api/old/ClassWithMethodVisibilitiesBeingChanged.php', |
48
|
|
|
$locator |
49
|
|
|
)))->reflect('RoaveTestAsset\\ClassWithMethodVisibilitiesBeingChanged'), |
50
|
|
|
(new ClassReflector(new SingleFileSourceLocator( |
51
|
|
|
__DIR__ . '/../../../../asset/api/new/ClassWithMethodVisibilitiesBeingChanged.php', |
52
|
|
|
$locator |
53
|
|
|
)))->reflect('RoaveTestAsset\\ClassWithMethodVisibilitiesBeingChanged'), |
54
|
|
|
[ |
55
|
|
|
'[BC] CHANGED: Method RoaveTestAsset\ClassWithMethodVisibilitiesBeingChanged#publicReducedToProtected() changed visibility from public to protected', |
56
|
|
|
'[BC] CHANGED: Method RoaveTestAsset\ClassWithMethodVisibilitiesBeingChanged#publicReducedToPrivate() changed visibility from public to private', |
57
|
|
|
'[BC] CHANGED: Method RoaveTestAsset\ClassWithMethodVisibilitiesBeingChanged#protectedReducedToPrivate() changed visibility from protected to private', |
58
|
|
|
], |
59
|
|
|
], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|