1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Roave\BackwardCompatibility\Change; |
10
|
|
|
use Roave\BackwardCompatibility\Changes; |
11
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantBased; |
12
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\OnlyPublicClassConstantChanged; |
13
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClassConstant; |
14
|
|
|
use function uniqid; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\OnlyPublicClassConstantChanged |
18
|
|
|
*/ |
19
|
|
|
final class OnlyPublicClassConstantChangedTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** @var ClassConstantBased&MockObject */ |
22
|
|
|
private $check; |
23
|
|
|
|
24
|
|
|
/** @var ReflectionClassConstant&MockObject */ |
25
|
|
|
private $fromConstant; |
26
|
|
|
|
27
|
|
|
/** @var ReflectionClassConstant&MockObject */ |
28
|
|
|
private $toConstant; |
29
|
|
|
|
30
|
|
|
/** @var OnlyPublicClassConstantChanged */ |
31
|
|
|
private $changed; |
32
|
|
|
|
33
|
|
|
protected function setUp() : void |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
|
37
|
|
|
$this->check = $this->createMock(ClassConstantBased::class); |
38
|
|
|
$this->changed = new OnlyPublicClassConstantChanged($this->check); |
39
|
|
|
$this->fromConstant = $this->createMock(ReflectionClassConstant::class); |
40
|
|
|
$this->toConstant = $this->createMock(ReflectionClassConstant::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testSkipsNonPublicConstant() : void |
44
|
|
|
{ |
45
|
|
|
$this |
46
|
|
|
->check |
47
|
|
|
->expects(self::never()) |
48
|
|
|
->method('__invoke'); |
49
|
|
|
|
50
|
|
|
$this |
51
|
|
|
->fromConstant |
52
|
|
|
->expects(self::any()) |
53
|
|
|
->method('isPublic') |
54
|
|
|
->willReturn(false); |
55
|
|
|
|
56
|
|
|
self::assertEquals( |
57
|
|
|
Changes::empty(), |
58
|
|
|
$this->changed->__invoke($this->fromConstant, $this->toConstant) |
59
|
|
|
); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function testChecksPublicConstant() : void |
63
|
|
|
{ |
64
|
|
|
$changes = Changes::fromList(Change::changed(uniqid('potato', true), true)); |
65
|
|
|
|
66
|
|
|
$this |
67
|
|
|
->check |
68
|
|
|
->expects(self::atLeastOnce()) |
69
|
|
|
->method('__invoke') |
70
|
|
|
->with($this->fromConstant, $this->toConstant) |
71
|
|
|
->willReturn($changes); |
72
|
|
|
|
73
|
|
|
$this |
74
|
|
|
->fromConstant |
75
|
|
|
->expects(self::any()) |
76
|
|
|
->method('isPublic') |
77
|
|
|
->willReturn(true); |
78
|
|
|
|
79
|
|
|
self::assertEquals( |
80
|
|
|
$changes, |
81
|
|
|
$this->changed->__invoke($this->fromConstant, $this->toConstant) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|