|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\MethodBased; |
|
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\MethodBased\AccessibleMethodChange; |
|
12
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\MethodBased; |
|
13
|
|
|
use Roave\BetterReflection\Reflection\ReflectionMethod; |
|
14
|
|
|
use function uniqid; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\AccessibleMethodChange |
|
18
|
|
|
*/ |
|
19
|
|
|
final class AccessibleMethodChangeTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var MethodBased|MockObject */ |
|
22
|
|
|
private $check; |
|
23
|
|
|
|
|
24
|
|
|
/** @var MethodBased */ |
|
25
|
|
|
private $methodCheck; |
|
26
|
|
|
|
|
27
|
|
|
protected function setUp() : void |
|
28
|
|
|
{ |
|
29
|
|
|
parent::setUp(); |
|
30
|
|
|
|
|
31
|
|
|
$this->check = $this->createMock(MethodBased::class); |
|
32
|
|
|
$this->methodCheck = new AccessibleMethodChange($this->check); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testWillSkipCheckingPrivateMethods() : void |
|
36
|
|
|
{ |
|
37
|
|
|
/** @var ReflectionMethod|MockObject $to */ |
|
38
|
|
|
$from = $this->createMock(ReflectionMethod::class); |
|
39
|
|
|
/** @var ReflectionMethod|MockObject $from */ |
|
40
|
|
|
$to = $this->createMock(ReflectionMethod::class); |
|
41
|
|
|
|
|
42
|
|
|
$from |
|
43
|
|
|
->expects(self::any()) |
|
|
|
|
|
|
44
|
|
|
->method('isPrivate') |
|
45
|
|
|
->willReturn(true); |
|
46
|
|
|
|
|
47
|
|
|
$this |
|
48
|
|
|
->check |
|
49
|
|
|
->expects(self::never()) |
|
|
|
|
|
|
50
|
|
|
->method('__invoke'); |
|
51
|
|
|
|
|
52
|
|
|
self::assertEquals(Changes::empty(), $this->methodCheck->__invoke($from, $to)); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function testWillCheckVisibleMethods() : void |
|
56
|
|
|
{ |
|
57
|
|
|
/** @var ReflectionMethod|MockObject $to */ |
|
58
|
|
|
$from = $this->createMock(ReflectionMethod::class); |
|
59
|
|
|
/** @var ReflectionMethod|MockObject $from */ |
|
60
|
|
|
$to = $this->createMock(ReflectionMethod::class); |
|
61
|
|
|
|
|
62
|
|
|
$from |
|
63
|
|
|
->expects(self::any()) |
|
64
|
|
|
->method('isPrivate') |
|
65
|
|
|
->willReturn(false); |
|
66
|
|
|
|
|
67
|
|
|
$result = Changes::fromList(Change::changed(uniqid('foo', true), true)); |
|
68
|
|
|
|
|
69
|
|
|
$this |
|
70
|
|
|
->check |
|
71
|
|
|
->expects(self::any()) |
|
72
|
|
|
->method('__invoke') |
|
73
|
|
|
->with($from, $to) |
|
74
|
|
|
->willReturn($result); |
|
75
|
|
|
|
|
76
|
|
|
self::assertEquals($result, $this->methodCheck->__invoke($from, $to)); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.