MethodChangedTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 60
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A testWillDetectChangesInMethods() 0 58 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassBased;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\BackwardCompatibility\Change;
9
use Roave\BackwardCompatibility\Changes;
10
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\MethodChanged;
11
use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\MethodBased;
12
use Roave\BetterReflection\BetterReflection;
13
use Roave\BetterReflection\Reflection\ReflectionMethod;
14
use Roave\BetterReflection\Reflector\ClassReflector;
15
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
16
use RoaveTest\BackwardCompatibility\Assertion;
17
use function strtolower;
18
19
/**
20
 * @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassBased\MethodChanged
21
 */
22
final class MethodChangedTest extends TestCase
23
{
24
    public function testWillDetectChangesInMethods() : void
25
    {
26
        $astLocator = (new BetterReflection())->astLocator();
27
28
        $fromLocator = new StringSourceLocator(
29
            <<<'PHP'
30
<?php
31
32
class TheClass {
33
    public function a() {}
34
    protected function b() {}
35
    private function c() {}
36
    private static function d() {}
37
    public function G() {}
38
}
39
PHP
40
            ,
41
            $astLocator
42
        );
43
44
        $toLocator = new StringSourceLocator(
45
            <<<'PHP'
46
<?php
47
48
class TheClass {
49
    protected function b() {}
50
    private static function d() {}
51
    public function e() {}
52
    public function f() {}
53
    public function g() {}
54
}
55
PHP
56
            ,
57
            $astLocator
58
        );
59
60
        $comparator = $this->createMock(MethodBased::class);
61
62
        $comparator
63
            ->expects(self::exactly(3))
64
            ->method('__invoke')
65
            ->willReturnCallback(static function (ReflectionMethod $from, ReflectionMethod $to) : Changes {
66
                $methodName = $from->getName();
67
68
                self::assertSame(strtolower($methodName), strtolower($to->getName()));
69
70
                return Changes::fromList(Change::added($methodName, true));
71
            });
72
73
        Assertion::assertChangesEqual(
74
            Changes::fromList(
75
                Change::added('b', true),
76
                Change::added('d', true),
77
                Change::added('G', true)
78
            ),
79
            (new MethodChanged($comparator))->__invoke(
80
                (new ClassReflector($fromLocator))->reflect('TheClass'),
81
                (new ClassReflector($toLocator))->reflect('TheClass')
82
            )
83
        );
84
    }
85
}
86