Passed
Pull Request — master (#50)
by Marco
02:46
created

OnlyProtectedMethodChangedTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testWillCheckProtectedMethods() 0 22 1
A setUp() 0 6 1
A testWillSkipCheckingNonProtectedMethods() 0 18 1
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
        /** @var ReflectionMethod|MockObject $to */
38
        $from = $this->createMock(ReflectionMethod::class);
39
        /** @var ReflectionMethod|MockObject $from */
40
        $to = $this->createMock(ReflectionMethod::class);
41
42
        $from
43
            ->expects(self::any())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BetterReflection\Reflection\ReflectionMethod. ( Ignorable by Annotation )

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

43
            ->/** @scrutinizer ignore-call */ 
44
              expects(self::any())

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...
44
            ->method('isProtected')
45
            ->willReturn(false);
46
47
        $this
48
            ->check
49
            ->expects(self::never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibil...MethodBased\MethodBased. ( Ignorable by Annotation )

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

49
            ->/** @scrutinizer ignore-call */ 
50
              expects(self::never())

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...
50
            ->method('__invoke');
51
52
        self::assertEquals(Changes::empty(), $this->methodCheck->__invoke($from, $to));
53
    }
54
55
    public function testWillCheckProtectedMethods() : void
56
    {
57
        /** @var ReflectionMethod|MockObject $to */
58
        $from = $this->createMock(ReflectionMethod::class);
59
        /** @var ReflectionMethod|MockObject $from */
60
        $to = $this->createMock(ReflectionMethod::class);
61
62
        $from
63
            ->expects(self::any())
64
            ->method('isProtected')
65
            ->willReturn(true);
66
67
        $result = Changes::fromList(Change::changed(uniqid('foo', true), true));
68
69
        $this
70
            ->check
71
            ->expects(self::any())
72
            ->method('__invoke')
73
            ->with($from, $to)
74
            ->willReturn($result);
75
76
        self::assertEquals($result, $this->methodCheck->__invoke($from, $to));
77
    }
78
}
79