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