|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Roave\BackwardCompatibility\Change; |
|
9
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\FunctionBecameInternal; |
|
10
|
|
|
use Roave\BetterReflection\BetterReflection; |
|
11
|
|
|
use Roave\BetterReflection\Reflection\ReflectionFunctionAbstract; |
|
12
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
|
13
|
|
|
use Roave\BetterReflection\Reflector\FunctionReflector; |
|
14
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
|
15
|
|
|
use function array_keys; |
|
16
|
|
|
use function array_map; |
|
17
|
|
|
use function iterator_to_array; |
|
18
|
|
|
use function Safe\array_combine; |
|
19
|
|
|
|
|
20
|
|
|
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\FunctionBecameInternal */ |
|
21
|
|
|
final class FunctionBecameInternalTest extends TestCase |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @param string[] $expectedMessages |
|
25
|
|
|
* |
|
26
|
|
|
* @dataProvider functionsToBeTested |
|
27
|
|
|
*/ |
|
28
|
|
|
public function testDiffs( |
|
29
|
|
|
ReflectionFunctionAbstract $fromFunction, |
|
30
|
|
|
ReflectionFunctionAbstract $toFunction, |
|
31
|
|
|
array $expectedMessages |
|
32
|
|
|
) : void { |
|
33
|
|
|
$changes = (new FunctionBecameInternal()) |
|
34
|
|
|
->__invoke($fromFunction, $toFunction); |
|
35
|
|
|
|
|
36
|
|
|
self::assertSame( |
|
|
|
|
|
|
37
|
|
|
$expectedMessages, |
|
|
|
|
|
|
38
|
|
|
array_map(static function (Change $change) : string { |
|
39
|
|
|
return $change->__toString(); |
|
40
|
|
|
}, iterator_to_array($changes)) |
|
41
|
|
|
); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* @return array<string, array<int, ReflectionFunctionAbstract|array<int, string>>> |
|
46
|
|
|
* |
|
47
|
|
|
* @psalm-return array<string, array{0: ReflectionFunctionAbstract, 1: ReflectionFunctionAbstract, 2: array<int, |
|
48
|
|
|
* string>}> |
|
49
|
|
|
*/ |
|
50
|
|
|
public function functionsToBeTested() : array |
|
51
|
|
|
{ |
|
52
|
|
|
$astLocator = (new BetterReflection())->astLocator(); |
|
53
|
|
|
|
|
54
|
|
|
$fromLocator = new StringSourceLocator( |
|
55
|
|
|
<<<'PHP' |
|
56
|
|
|
<?php |
|
57
|
|
|
|
|
58
|
|
|
function a() {} |
|
59
|
|
|
function b() {} |
|
60
|
|
|
/** @internal */ |
|
61
|
|
|
function c() {} |
|
62
|
|
|
/** @internal */ |
|
63
|
|
|
function d() {} |
|
64
|
|
|
PHP |
|
65
|
|
|
, |
|
66
|
|
|
$astLocator |
|
67
|
|
|
); |
|
68
|
|
|
|
|
69
|
|
|
$toLocator = new StringSourceLocator( |
|
70
|
|
|
<<<'PHP' |
|
71
|
|
|
<?php |
|
72
|
|
|
|
|
73
|
|
|
function a() {} |
|
74
|
|
|
/** @internal */ |
|
75
|
|
|
function b() {} |
|
76
|
|
|
function c() {} |
|
77
|
|
|
/** @internal */ |
|
78
|
|
|
function d() {} |
|
79
|
|
|
PHP |
|
80
|
|
|
, |
|
81
|
|
|
$astLocator |
|
82
|
|
|
); |
|
83
|
|
|
|
|
84
|
|
|
$fromClassReflector = new ClassReflector($fromLocator); |
|
85
|
|
|
$toClassReflector = new ClassReflector($toLocator); |
|
86
|
|
|
$fromReflector = new FunctionReflector($fromLocator, $fromClassReflector); |
|
87
|
|
|
$toReflector = new FunctionReflector($toLocator, $toClassReflector); |
|
88
|
|
|
|
|
89
|
|
|
$functions = [ |
|
90
|
|
|
'a' => [], |
|
91
|
|
|
'b' => ['[BC] CHANGED: b() was marked "@internal"'], |
|
92
|
|
|
'c' => [], |
|
93
|
|
|
'd' => [], |
|
94
|
|
|
]; |
|
95
|
|
|
|
|
96
|
|
|
return array_combine( |
|
97
|
|
|
array_keys($functions), |
|
98
|
|
|
array_map( |
|
99
|
|
|
static function (string $function, array $errorMessages) use ($fromReflector, $toReflector) : array { |
|
100
|
|
|
return [ |
|
101
|
|
|
$fromReflector->reflect($function), |
|
102
|
|
|
$toReflector->reflect($function), |
|
103
|
|
|
$errorMessages, |
|
104
|
|
|
]; |
|
105
|
|
|
}, |
|
106
|
|
|
array_keys($functions), |
|
107
|
|
|
$functions |
|
108
|
|
|
) |
|
109
|
|
|
); |
|
110
|
|
|
} |
|
111
|
|
|
} |
|
112
|
|
|
|