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\Changes; |
10
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ClassBased; |
11
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\ExcludeAnonymousClasses; |
12
|
|
|
use Roave\BetterReflection\BetterReflection; |
13
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
14
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
15
|
|
|
use function reset; |
16
|
|
|
|
17
|
|
|
final class ExcludeAnonymousClassesTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
public function testNormalClassesAreNotExcluded() : void |
20
|
|
|
{ |
21
|
|
|
$locator = (new BetterReflection())->astLocator(); |
22
|
|
|
$reflector = new ClassReflector(new StringSourceLocator( |
23
|
|
|
<<<'PHP' |
24
|
|
|
<?php |
25
|
|
|
|
26
|
|
|
class ANormalClass {} |
27
|
|
|
PHP |
28
|
|
|
, |
29
|
|
|
$locator |
30
|
|
|
)); |
31
|
|
|
$fromReflection = $reflector->reflect('ANormalClass'); |
32
|
|
|
$toReflection = $reflector->reflect('ANormalClass'); |
33
|
|
|
|
34
|
|
|
/** @var ClassBased|MockObject $check */ |
35
|
|
|
$check = $this->createMock(ClassBased::class); |
36
|
|
|
$check->expects(self::once()) |
|
|
|
|
37
|
|
|
->method('__invoke') |
38
|
|
|
->with($fromReflection, $toReflection) |
39
|
|
|
->willReturn(Changes::empty()); |
40
|
|
|
|
41
|
|
|
$excluder = new ExcludeAnonymousClasses($check); |
42
|
|
|
$excluder->__invoke($fromReflection, $toReflection); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function testAnonymousClassesAreExcluded() : void |
46
|
|
|
{ |
47
|
|
|
$locator = (new BetterReflection())->astLocator(); |
48
|
|
|
$reflector = new ClassReflector(new StringSourceLocator( |
49
|
|
|
<<<'PHP' |
50
|
|
|
<?php |
51
|
|
|
|
52
|
|
|
$anonClass = new class {}; |
53
|
|
|
PHP |
54
|
|
|
, |
55
|
|
|
$locator |
56
|
|
|
)); |
57
|
|
|
$allClasses = $reflector->getAllClasses(); |
58
|
|
|
$anonymousClassReflection = reset($allClasses); |
59
|
|
|
|
60
|
|
|
/** @var ClassBased|MockObject $check */ |
61
|
|
|
$check = $this->createMock(ClassBased::class); |
62
|
|
|
$check->expects(self::never())->method('__invoke'); |
63
|
|
|
|
64
|
|
|
$excluder = new ExcludeAnonymousClasses($check); |
65
|
|
|
$excluder->__invoke($anonymousClassReflection, $anonymousClassReflection); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.