Passed
Pull Request — master (#60)
by James
03:22
created

ExcludeAnonymousClassesTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testAnonymousClassesAreExcluded() 0 21 1
B testNormalClassesAreNotExcluded() 0 24 1
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())
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

36
        $check->/** @scrutinizer ignore-call */ 
37
                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...
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