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