Passed
Pull Request — master (#38)
by Marco
02:55
created

AccessibleMethodFunctionBasedChangeTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testWillSkipCheckingPrivateMethods() 0 18 1
B testWillCheckVisibleMethods() 0 24 1
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\FunctionBased\FunctionBased;
12
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\AccessibleMethodFunctionBasedChange;
13
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\MethodBased;
14
use Roave\BetterReflection\Reflection\ReflectionMethod;
15
16
final class AccessibleMethodFunctionBasedChangeTest extends TestCase
17
{
18
    /** @var FunctionBased|MockObject */
19
    private $functionCheck;
20
21
    /** @var MethodBased */
22
    private $methodCheck;
23
24
    protected function setUp()
25
    {
26
        parent::setUp();
27
28
        $this->functionCheck = $this->createMock(FunctionBased::class);
29
        $this->methodCheck   = new AccessibleMethodFunctionBasedChange($this->functionCheck);
30
    }
31
32
    public function testWillSkipCheckingPrivateMethods() : void
33
    {
34
        /** @var ReflectionMethod|MockObject $to */
35
        $from = $this->createMock(ReflectionMethod::class);
36
        /** @var ReflectionMethod|MockObject $from */
37
        $to = $this->createMock(ReflectionMethod::class);
38
39
        $from
40
            ->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

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

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

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