ExcludeInternalMethodTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 31
c 1
b 0
f 0
dl 0
loc 56
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testNormalMethodsAreNotExcluded() 0 26 1
A testInternalFunctionsAreExcluded() 0 25 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\MethodBased;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\BackwardCompatibility\Change;
9
use Roave\BackwardCompatibility\Changes;
10
use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\ExcludeInternalMethod;
11
use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\MethodBased;
12
use Roave\BetterReflection\BetterReflection;
13
use Roave\BetterReflection\Reflector\ClassReflector;
14
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
15
16
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\ExcludeInternalMethod */
17
final class ExcludeInternalMethodTest extends TestCase
18
{
19
    public function testNormalMethodsAreNotExcluded() : void
20
    {
21
        $method = (new ClassReflector(new StringSourceLocator(
22
            <<<'PHP'
23
<?php
24
25
class A {
26
    function method() {}
27
}
28
PHP
29
            ,
30
            (new BetterReflection())->astLocator()
31
        )))
32
            ->reflect('A')
33
            ->getMethod('method');
34
35
        $check = $this->createMock(MethodBased::class);
36
        $check->expects(self::once())
37
              ->method('__invoke')
38
              ->with($method, $method)
39
              ->willReturn(Changes::fromList(Change::removed('foo', true)));
40
41
        self::assertEquals(
42
            Changes::fromList(Change::removed('foo', true)),
43
            (new ExcludeInternalMethod($check))
44
                ->__invoke($method, $method)
45
        );
46
    }
47
48
    public function testInternalFunctionsAreExcluded() : void
49
    {
50
        $method = (new ClassReflector(new StringSourceLocator(
51
            <<<'PHP'
52
<?php
53
54
class A {
55
    /** @internal */
56
    function method() {}
57
}
58
PHP
59
            ,
60
            (new BetterReflection())->astLocator()
61
        )))
62
            ->reflect('A')
63
            ->getMethod('method');
64
65
        $check = $this->createMock(MethodBased::class);
66
        $check->expects(self::never())
67
              ->method('__invoke');
68
69
        self::assertEquals(
70
            Changes::empty(),
71
            (new ExcludeInternalMethod($check))
72
                ->__invoke($method, $method)
73
        );
74
    }
75
}
76