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