1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Roave\BackwardCompatibility\Change; |
9
|
|
|
use Roave\BackwardCompatibility\Changes; |
10
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ExcludeInternalFunction; |
11
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\FunctionBased; |
12
|
|
|
use Roave\BetterReflection\BetterReflection; |
13
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
14
|
|
|
use Roave\BetterReflection\Reflector\FunctionReflector; |
15
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
16
|
|
|
|
17
|
|
|
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\FunctionBased\ExcludeInternalFunction */ |
18
|
|
|
final class ExcludeInternalFunctionTest extends TestCase |
19
|
|
|
{ |
20
|
|
|
public function testNormalFunctionsAreNotExcluded() : void |
21
|
|
|
{ |
22
|
|
|
$source = new StringSourceLocator( |
23
|
|
|
<<<'PHP' |
24
|
|
|
<?php |
25
|
|
|
|
26
|
|
|
function a() {} |
27
|
|
|
PHP |
28
|
|
|
, |
29
|
|
|
(new BetterReflection())->astLocator() |
30
|
|
|
); |
31
|
|
|
$function = (new FunctionReflector($source, new ClassReflector($source))) |
32
|
|
|
->reflect('a'); |
33
|
|
|
|
34
|
|
|
$check = $this->createMock(FunctionBased::class); |
35
|
|
|
$check->expects(self::once()) |
|
|
|
|
36
|
|
|
->method('__invoke') |
37
|
|
|
->with($function, $function) |
38
|
|
|
->willReturn(Changes::fromList(Change::removed('foo', true))); |
39
|
|
|
|
40
|
|
|
self::assertEquals( |
|
|
|
|
41
|
|
|
Changes::fromList(Change::removed('foo', true)), |
42
|
|
|
(new ExcludeInternalFunction($check)) |
43
|
|
|
->__invoke($function, $function) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testInternalFunctionsAreExcluded() : void |
48
|
|
|
{ |
49
|
|
|
$source = new StringSourceLocator( |
50
|
|
|
<<<'PHP' |
51
|
|
|
<?php |
52
|
|
|
|
53
|
|
|
/** @internal */ |
54
|
|
|
function a() {} |
55
|
|
|
PHP |
56
|
|
|
, |
57
|
|
|
(new BetterReflection())->astLocator() |
58
|
|
|
); |
59
|
|
|
$function = (new FunctionReflector($source, new ClassReflector($source))) |
60
|
|
|
->reflect('a'); |
61
|
|
|
|
62
|
|
|
$check = $this->createMock(FunctionBased::class); |
63
|
|
|
$check->expects(self::never()) |
|
|
|
|
64
|
|
|
->method('__invoke'); |
65
|
|
|
|
66
|
|
|
self::assertEquals( |
67
|
|
|
Changes::empty(), |
68
|
|
|
(new ExcludeInternalFunction($check)) |
69
|
|
|
->__invoke($function, $function) |
70
|
|
|
); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
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.