|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased; |
|
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\PropertyBased\OnlyProtectedPropertyChanged; |
|
12
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased\PropertyBased; |
|
13
|
|
|
use Roave\BetterReflection\Reflection\ReflectionProperty; |
|
14
|
|
|
use function uniqid; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased\OnlyProtectedPropertyChanged |
|
18
|
|
|
*/ |
|
19
|
|
|
final class OnlyProtectedPropertyChangedTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var PropertyBased&MockObject */ |
|
22
|
|
|
private $check; |
|
23
|
|
|
|
|
24
|
|
|
/** @var ReflectionProperty&MockObject */ |
|
25
|
|
|
private $fromProperty; |
|
26
|
|
|
|
|
27
|
|
|
/** @var ReflectionProperty&MockObject */ |
|
28
|
|
|
private $toProperty; |
|
29
|
|
|
|
|
30
|
|
|
/** @var OnlyProtectedPropertyChanged */ |
|
31
|
|
|
private $changed; |
|
32
|
|
|
|
|
33
|
|
|
protected function setUp() : void |
|
34
|
|
|
{ |
|
35
|
|
|
parent::setUp(); |
|
36
|
|
|
|
|
37
|
|
|
$this->check = $this->createMock(PropertyBased::class); |
|
38
|
|
|
$this->changed = new OnlyProtectedPropertyChanged($this->check); |
|
39
|
|
|
$this->fromProperty = $this->createMock(ReflectionProperty::class); |
|
40
|
|
|
$this->toProperty = $this->createMock(ReflectionProperty::class); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function testSkipsNonProtectedProperty() : void |
|
44
|
|
|
{ |
|
45
|
|
|
$this |
|
46
|
|
|
->check |
|
47
|
|
|
->expects(self::never()) |
|
48
|
|
|
->method('__invoke'); |
|
49
|
|
|
|
|
50
|
|
|
$this |
|
51
|
|
|
->fromProperty |
|
52
|
|
|
->expects(self::any()) |
|
53
|
|
|
->method('isProtected') |
|
54
|
|
|
->willReturn(false); |
|
55
|
|
|
|
|
56
|
|
|
self::assertEquals( |
|
57
|
|
|
Changes::empty(), |
|
58
|
|
|
$this->changed->__invoke($this->fromProperty, $this->toProperty) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testChecksProtectedProperty() : 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->fromProperty, $this->toProperty) |
|
71
|
|
|
->willReturn($changes); |
|
72
|
|
|
|
|
73
|
|
|
$this |
|
74
|
|
|
->fromProperty |
|
75
|
|
|
->expects(self::any()) |
|
76
|
|
|
->method('isProtected') |
|
77
|
|
|
->willReturn(true); |
|
78
|
|
|
|
|
79
|
|
|
self::assertEquals( |
|
80
|
|
|
$changes, |
|
81
|
|
|
$this->changed->__invoke($this->fromProperty, $this->toProperty) |
|
82
|
|
|
); |
|
83
|
|
|
} |
|
84
|
|
|
} |
|
85
|
|
|
|