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