Completed
Pull Request — master (#60)
by James
03:26
created

testAnonymousClassesAreExcluded()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 21
rs 9.3142
c 0
b 0
f 0
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())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibil...k\ClassBased\ClassBased. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        $check->/** @scrutinizer ignore-call */ 
36
                expects(self::once())

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.

Loading history...
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