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\Changes; |
10
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ConstantChanged; |
11
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantBased; |
12
|
|
|
use Roave\BetterReflection\BetterReflection; |
13
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClassConstant; |
14
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
15
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
16
|
|
|
use RoaveTest\BackwardCompatibility\Assertion; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ConstantChanged |
20
|
|
|
*/ |
21
|
|
|
final class ConstantChangedTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testWillDetectChangesInConstants() : void |
24
|
|
|
{ |
25
|
|
|
$astLocator = (new BetterReflection())->astLocator(); |
26
|
|
|
|
27
|
|
|
$fromLocator = new StringSourceLocator( |
28
|
|
|
<<<'PHP' |
29
|
|
|
<?php |
30
|
|
|
|
31
|
|
|
class TheClass { |
32
|
|
|
public const a = 'value'; |
33
|
|
|
protected const b = 'value'; |
34
|
|
|
private const c = 'value'; |
35
|
|
|
public const d = 'value'; |
36
|
|
|
public const G = 'value'; |
37
|
|
|
} |
38
|
|
|
PHP |
39
|
|
|
, |
40
|
|
|
$astLocator |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$toLocator = new StringSourceLocator( |
44
|
|
|
<<<'PHP' |
45
|
|
|
<?php |
46
|
|
|
|
47
|
|
|
class TheClass { |
48
|
|
|
protected const b = 'value'; |
49
|
|
|
public const d = 'value'; |
50
|
|
|
public const e = 'value'; |
51
|
|
|
public const f = 'value'; |
52
|
|
|
public const g = 'value'; |
53
|
|
|
} |
54
|
|
|
PHP |
55
|
|
|
, |
56
|
|
|
$astLocator |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$comparator = $this->createMock(ClassConstantBased::class); |
60
|
|
|
|
61
|
|
|
$comparator |
62
|
|
|
->expects(self::exactly(2)) |
63
|
|
|
->method('__invoke') |
64
|
|
|
->willReturnCallback(static function (ReflectionClassConstant $from, ReflectionClassConstant $to) : Changes { |
65
|
|
|
$propertyName = $from->getName(); |
66
|
|
|
|
67
|
|
|
self::assertSame($propertyName, $to->getName()); |
68
|
|
|
|
69
|
|
|
return Changes::fromList(Change::added($propertyName, true)); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
Assertion::assertChangesEqual( |
73
|
|
|
Changes::fromList( |
74
|
|
|
Change::added('b', true), |
75
|
|
|
Change::added('d', true) |
76
|
|
|
), |
77
|
|
|
(new ConstantChanged($comparator))->__invoke( |
78
|
|
|
(new ClassReflector($fromLocator))->reflect('TheClass'), |
79
|
|
|
(new ClassReflector($toLocator))->reflect('TheClass') |
80
|
|
|
) |
81
|
|
|
); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|