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\MethodBased; |
12
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\OnlyProtectedMethodChanged; |
13
|
|
|
use Roave\BetterReflection\Reflection\ReflectionMethod; |
14
|
|
|
use function uniqid; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\OnlyProtectedMethodChanged |
18
|
|
|
*/ |
19
|
|
|
final class OnlyProtectedMethodChangedTest extends TestCase |
20
|
|
|
{ |
21
|
|
|
/** @var MethodBased|MockObject */ |
22
|
|
|
private $check; |
23
|
|
|
|
24
|
|
|
/** @var OnlyProtectedMethodChanged */ |
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 OnlyProtectedMethodChanged($this->check); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testWillSkipCheckingNonProtectedMethods() : 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('isProtected') |
45
|
|
|
->willReturn(false); |
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 testWillCheckProtectedMethods() : 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('isProtected') |
65
|
|
|
->willReturn(true); |
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.