testWillSkipCheckingNonProtectedMethods()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 0
dl 0
loc 16
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\MethodBased;
6
7
use PHPUnit\Framework\MockObject\MockObject;
8
use PHPUnit\Framework\TestCase;
9
use Roave\BackwardCompatibility\Change;
10
use Roave\BackwardCompatibility\Changes;
11
use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\MethodBased;
12
use Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\OnlyProtectedMethodChanged;
13
use Roave\BetterReflection\Reflection\ReflectionMethod;
14
use function uniqid;
15
16
/**
17
 * @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\MethodBased\OnlyProtectedMethodChanged
18
 */
19
final class OnlyProtectedMethodChangedTest extends TestCase
20
{
21
    /** @var MethodBased&MockObject */
22
    private $check;
23
24
    /** @var OnlyProtectedMethodChanged */
25
    private $methodCheck;
26
27
    protected function setUp() : void
28
    {
29
        parent::setUp();
30
31
        $this->check       = $this->createMock(MethodBased::class);
32
        $this->methodCheck = new OnlyProtectedMethodChanged($this->check);
33
    }
34
35
    public function testWillSkipCheckingNonProtectedMethods() : void
36
    {
37
        $from = $this->createMock(ReflectionMethod::class);
38
        $to   = $this->createMock(ReflectionMethod::class);
39
40
        $from
41
            ->expects(self::any())
42
            ->method('isProtected')
43
            ->willReturn(false);
44
45
        $this
46
            ->check
47
            ->expects(self::never())
48
            ->method('__invoke');
49
50
        self::assertEquals(Changes::empty(), $this->methodCheck->__invoke($from, $to));
51
    }
52
53
    public function testWillCheckProtectedMethods() : void
54
    {
55
        $from = $this->createMock(ReflectionMethod::class);
56
        $to   = $this->createMock(ReflectionMethod::class);
57
58
        $from
59
            ->expects(self::any())
60
            ->method('isProtected')
61
            ->willReturn(true);
62
63
        $result = Changes::fromList(Change::changed(uniqid('foo', true), true));
64
65
        $this
66
            ->check
67
            ->expects(self::any())
68
            ->method('__invoke')
69
            ->with($from, $to)
70
            ->willReturn($result);
71
72
        self::assertEquals($result, $this->methodCheck->__invoke($from, $to));
73
    }
74
}
75