1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Roave\BackwardCompatibility\Change; |
9
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ClassBecameInternal; |
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_map; |
15
|
|
|
use function iterator_to_array; |
16
|
|
|
|
17
|
|
|
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ClassBecameInternal */ |
18
|
|
|
final class ClassBecameInternalTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @param string[] $expectedMessages |
22
|
|
|
* |
23
|
|
|
* @dataProvider classesToBeTested |
24
|
|
|
*/ |
25
|
|
|
public function testDiffs( |
26
|
|
|
ReflectionClass $fromClass, |
27
|
|
|
ReflectionClass $toClass, |
28
|
|
|
array $expectedMessages |
29
|
|
|
) : void { |
30
|
|
|
$changes = (new ClassBecameInternal()) |
31
|
|
|
->__invoke($fromClass, $toClass); |
32
|
|
|
|
33
|
|
|
self::assertSame( |
|
|
|
|
34
|
|
|
$expectedMessages, |
|
|
|
|
35
|
|
|
array_map(static function (Change $change) : string { |
36
|
|
|
return $change->__toString(); |
37
|
|
|
}, iterator_to_array($changes)) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @return array<string, array<int, ReflectionClass|array<int, string>>> |
43
|
|
|
* |
44
|
|
|
* @psalm-return array<string, array{0: ReflectionClass, 1: ReflectionClass, 2: array<int, string>}> |
45
|
|
|
*/ |
46
|
|
|
public function classesToBeTested() : array |
47
|
|
|
{ |
48
|
|
|
$locator = (new BetterReflection())->astLocator(); |
49
|
|
|
$fromReflector = new ClassReflector(new StringSourceLocator( |
50
|
|
|
<<<'PHP' |
51
|
|
|
<?php |
52
|
|
|
|
53
|
|
|
class A {} |
54
|
|
|
class B {} |
55
|
|
|
/** @internal */ |
56
|
|
|
class C {} |
57
|
|
|
/** @internal */ |
58
|
|
|
class D {} |
59
|
|
|
PHP |
60
|
|
|
, |
61
|
|
|
$locator |
62
|
|
|
)); |
63
|
|
|
$toReflector = new ClassReflector(new StringSourceLocator( |
64
|
|
|
<<<'PHP' |
65
|
|
|
<?php |
66
|
|
|
|
67
|
|
|
class A {} |
68
|
|
|
/** @internal */ |
69
|
|
|
class B {} |
70
|
|
|
/** @internal */ |
71
|
|
|
class C {} |
72
|
|
|
class D {} |
73
|
|
|
PHP |
74
|
|
|
, |
75
|
|
|
$locator |
76
|
|
|
)); |
77
|
|
|
|
78
|
|
|
return [ |
79
|
|
|
'A' => [ |
80
|
|
|
$fromReflector->reflect('A'), |
81
|
|
|
$toReflector->reflect('A'), |
82
|
|
|
[], |
83
|
|
|
], |
84
|
|
|
'B' => [ |
85
|
|
|
$fromReflector->reflect('B'), |
86
|
|
|
$toReflector->reflect('B'), |
87
|
|
|
['[BC] CHANGED: B was marked "@internal"'], |
88
|
|
|
], |
89
|
|
|
'C' => [ |
90
|
|
|
$fromReflector->reflect('C'), |
91
|
|
|
$toReflector->reflect('C'), |
92
|
|
|
[], |
93
|
|
|
], |
94
|
|
|
'D' => [ |
95
|
|
|
$fromReflector->reflect('D'), |
96
|
|
|
$toReflector->reflect('D'), |
97
|
|
|
[], |
98
|
|
|
], |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|