1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\ClassBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\MockObject\MockObject; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
use Roave\ApiCompare\Change; |
10
|
|
|
use Roave\ApiCompare\Changes; |
11
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\ClassBased; |
12
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\FinalClassChanged; |
13
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\OpenClassChanged; |
14
|
|
|
use Roave\BetterReflection\Reflection\ReflectionClass; |
15
|
|
|
use function uniqid; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\OpenClassChanged |
19
|
|
|
*/ |
20
|
|
|
final class OpenClassChangedTest extends TestCase |
21
|
|
|
{ |
22
|
|
|
/** @var ClassBased|MockObject */ |
23
|
|
|
private $check; |
24
|
|
|
|
25
|
|
|
/** @var FinalClassChanged */ |
26
|
|
|
private $openClassChanged; |
27
|
|
|
|
28
|
|
|
/** @var ReflectionClass|MockObject */ |
29
|
|
|
private $fromClass; |
30
|
|
|
|
31
|
|
|
/** @var ReflectionClass|MockObject */ |
32
|
|
|
private $toClass; |
33
|
|
|
|
34
|
|
|
protected function setUp() : void |
35
|
|
|
{ |
36
|
|
|
parent::setUp(); |
37
|
|
|
|
38
|
|
|
$this->check = $this->createMock(ClassBased::class); |
39
|
|
|
$this->openClassChanged = new OpenClassChanged($this->check); |
|
|
|
|
40
|
|
|
$this->fromClass = $this->createMock(ReflectionClass::class); |
41
|
|
|
$this->toClass = $this->createMock(ReflectionClass::class); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function testWillCheckFinalClass() : void |
45
|
|
|
{ |
46
|
|
|
$changes = Changes::fromArray([Change::added(uniqid('carrot', true), true)]); |
47
|
|
|
|
48
|
|
|
$this |
49
|
|
|
->fromClass |
50
|
|
|
->expects(self::any()) |
|
|
|
|
51
|
|
|
->method('isFinal') |
52
|
|
|
->willReturn(false); |
53
|
|
|
|
54
|
|
|
$this |
55
|
|
|
->check |
56
|
|
|
->expects(self::atLeastOnce()) |
|
|
|
|
57
|
|
|
->method('compare') |
58
|
|
|
->with($this->fromClass, $this->toClass) |
59
|
|
|
->willReturn($changes); |
60
|
|
|
|
61
|
|
|
self::assertEquals($changes, $this->openClassChanged->compare($this->fromClass, $this->toClass)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testWillNotCheckOpenClass() : void |
65
|
|
|
{ |
66
|
|
|
$this |
67
|
|
|
->fromClass |
68
|
|
|
->expects(self::any()) |
69
|
|
|
->method('isFinal') |
70
|
|
|
->willReturn(true); |
71
|
|
|
|
72
|
|
|
$this |
73
|
|
|
->check |
74
|
|
|
->expects(self::never()) |
75
|
|
|
->method('compare'); |
76
|
|
|
|
77
|
|
|
self::assertEquals(Changes::new(), $this->openClassChanged->compare($this->fromClass, $this->toClass)); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..