1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassBased; |
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\ClassBased\ClassBased; |
12
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\FinalClassChanged; |
13
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClass; |
14
|
|
|
use function uniqid; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\FinalClassChanged |
18
|
|
|
*/ |
19
|
|
|
final class FinalClassChangedTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** @var ClassBased&MockObject */ |
22
|
|
|
private $check; |
23
|
|
|
|
24
|
|
|
/** @var FinalClassChanged */ |
25
|
|
|
private $finalClassChanged; |
26
|
|
|
|
27
|
|
|
/** @var ReflectionClass&MockObject */ |
28
|
|
|
private $fromClass; |
29
|
|
|
|
30
|
|
|
/** @var ReflectionClass&MockObject */ |
31
|
|
|
private $toClass; |
32
|
|
|
|
33
|
|
|
protected function setUp() : void |
34
|
|
|
{ |
35
|
|
|
parent::setUp(); |
36
|
|
|
|
37
|
|
|
$this->check = $this->createMock(ClassBased::class); |
38
|
|
|
$this->finalClassChanged = new FinalClassChanged($this->check); |
39
|
|
|
$this->fromClass = $this->createMock(ReflectionClass::class); |
40
|
|
|
$this->toClass = $this->createMock(ReflectionClass::class); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public function testWillCheckFinalClass() : void |
44
|
|
|
{ |
45
|
|
|
$changes = Changes::fromList(Change::added(uniqid('carrot', true), true)); |
46
|
|
|
|
47
|
|
|
$this |
48
|
|
|
->fromClass |
49
|
|
|
->expects(self::any()) |
50
|
|
|
->method('isFinal') |
51
|
|
|
->willReturn(true); |
52
|
|
|
|
53
|
|
|
$this |
54
|
|
|
->check |
55
|
|
|
->expects(self::atLeastOnce()) |
56
|
|
|
->method('__invoke') |
57
|
|
|
->with($this->fromClass, $this->toClass) |
58
|
|
|
->willReturn($changes); |
59
|
|
|
|
60
|
|
|
self::assertEquals($changes, $this->finalClassChanged->__invoke($this->fromClass, $this->toClass)); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testWillNotCheckOpenClass() : void |
64
|
|
|
{ |
65
|
|
|
$this |
66
|
|
|
->fromClass |
67
|
|
|
->expects(self::any()) |
68
|
|
|
->method('isFinal') |
69
|
|
|
->willReturn(false); |
70
|
|
|
|
71
|
|
|
$this |
72
|
|
|
->check |
73
|
|
|
->expects(self::never()) |
74
|
|
|
->method('__invoke'); |
75
|
|
|
|
76
|
|
|
self::assertEquals(Changes::empty(), $this->finalClassChanged->__invoke($this->fromClass, $this->toClass)); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|