Completed
Pull Request — master (#38)
by Marco
03:08
created

testWillSkipCheckingPrivateMethods()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\MethodBased;
6
7
use PHPUnit\Framework\MockObject\MockObject;
8
use PHPUnit\Framework\TestCase;
9
use Roave\ApiCompare\Change;
10
use Roave\ApiCompare\Changes;
11
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\AccessibleMethodChange;
12
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\MethodBased;
13
use Roave\BetterReflection\Reflection\ReflectionMethod;
14
15
/**
16
 * @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\AccessibleMethodChange
17
 */
18
final class AccessibleMethodChangeTest extends TestCase
19
{
20
    /** @var MethodBased|MockObject */
21
    private $check;
22
23
    /** @var MethodBased */
24
    private $methodCheck;
25
26
    protected function setUp()
27
    {
28
        parent::setUp();
29
30
        $this->check       = $this->createMock(MethodBased::class);
31
        $this->methodCheck = new AccessibleMethodChange($this->check);
32
    }
33
34
    public function testWillSkipCheckingPrivateMethods() : void
35
    {
36
        /** @var ReflectionMethod|MockObject $to */
37
        $from = $this->createMock(ReflectionMethod::class);
38
        /** @var ReflectionMethod|MockObject $from */
39
        $to = $this->createMock(ReflectionMethod::class);
40
41
        $from
42
            ->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

42
            ->/** @scrutinizer ignore-call */ 
43
              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...
43
            ->method('isPrivate')
44
            ->willReturn(true);
45
46
        $this
47
            ->check
48
            ->expects(self::never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\ApiCompare\Compara...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

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