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