|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\MethodBased; |
|
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\FunctionBased\FunctionBased; |
|
12
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\AccessibleMethodFunctionBasedChange; |
|
13
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\MethodBased; |
|
14
|
|
|
use Roave\BetterReflection\Reflection\ReflectionMethod; |
|
15
|
|
|
|
|
16
|
|
|
final class AccessibleMethodFunctionBasedChangeTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var FunctionBased|MockObject */ |
|
19
|
|
|
private $functionCheck; |
|
20
|
|
|
|
|
21
|
|
|
/** @var MethodBased */ |
|
22
|
|
|
private $methodCheck; |
|
23
|
|
|
|
|
24
|
|
|
protected function setUp() |
|
25
|
|
|
{ |
|
26
|
|
|
parent::setUp(); |
|
27
|
|
|
|
|
28
|
|
|
$this->functionCheck = $this->createMock(FunctionBased::class); |
|
29
|
|
|
$this->methodCheck = new AccessibleMethodFunctionBasedChange($this->functionCheck); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function testWillSkipCheckingPrivateMethods() : void |
|
33
|
|
|
{ |
|
34
|
|
|
/** @var ReflectionMethod|MockObject $to */ |
|
35
|
|
|
$from = $this->createMock(ReflectionMethod::class); |
|
36
|
|
|
/** @var ReflectionMethod|MockObject $from */ |
|
37
|
|
|
$to = $this->createMock(ReflectionMethod::class); |
|
38
|
|
|
|
|
39
|
|
|
$from |
|
40
|
|
|
->expects(self::any()) |
|
|
|
|
|
|
41
|
|
|
->method('isPrivate') |
|
42
|
|
|
->willReturn(true); |
|
43
|
|
|
|
|
44
|
|
|
$this |
|
45
|
|
|
->functionCheck |
|
46
|
|
|
->expects(self::never()) |
|
|
|
|
|
|
47
|
|
|
->method('compare'); |
|
48
|
|
|
|
|
49
|
|
|
self::assertEquals(Changes::new(), $this->methodCheck->compare($from, $to)); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testWillCheckVisibleMethods() : void |
|
53
|
|
|
{ |
|
54
|
|
|
/** @var ReflectionMethod|MockObject $to */ |
|
55
|
|
|
$from = $this->createMock(ReflectionMethod::class); |
|
56
|
|
|
/** @var ReflectionMethod|MockObject $from */ |
|
57
|
|
|
$to = $this->createMock(ReflectionMethod::class); |
|
58
|
|
|
|
|
59
|
|
|
$from |
|
60
|
|
|
->expects(self::any()) |
|
61
|
|
|
->method('isPrivate') |
|
62
|
|
|
->willReturn(false); |
|
63
|
|
|
|
|
64
|
|
|
$result = Changes::fromArray([ |
|
65
|
|
|
Change::changed(uniqid('foo', true), true), |
|
66
|
|
|
]); |
|
67
|
|
|
|
|
68
|
|
|
$this |
|
69
|
|
|
->functionCheck |
|
70
|
|
|
->expects(self::any()) |
|
71
|
|
|
->method('compare') |
|
72
|
|
|
->with($from, $to) |
|
73
|
|
|
->willReturn($result); |
|
74
|
|
|
|
|
75
|
|
|
self::assertEquals($result, $this->methodCheck->compare($from, $to)); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
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.