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

testChecksPublicProperty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased;
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\PropertyBased\OnlyPublicPropertyChanged;
12
use Roave\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased\PropertyBased;
13
use Roave\BetterReflection\Reflection\ReflectionProperty;
14
use function uniqid;
15
16
/**
17
 * @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased\OnlyPublicPropertyChanged
18
 */
19
final class OnlyPublicPropertyChangedTest extends TestCase
20
{
21
    /** @var PropertyBased|MockObject */
22
    private $check;
23
24
    /** @var ReflectionProperty|MockObject */
25
    private $fromProperty;
26
27
    /** @var ReflectionProperty|MockObject */
28
    private $toProperty;
29
30
    /** @var OnlyPublicPropertyChanged */
31
    private $changed;
32
33
    protected function setUp() : void
34
    {
35
        parent::setUp();
36
37
        $this->check        = $this->createMock(PropertyBased::class);
38
        $this->changed      = new OnlyPublicPropertyChanged($this->check);
39
        $this->fromProperty = $this->createMock(ReflectionProperty::class);
40
        $this->toProperty   = $this->createMock(ReflectionProperty::class);
41
    }
42
43
    public function testSkipsNonPublicProperty() : void
44
    {
45
        $this
46
            ->check
47
            ->expects(self::never())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\ApiCompare\Compara...ertyBased\PropertyBased. ( Ignorable by Annotation )

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

47
            ->/** @scrutinizer ignore-call */ 
48
              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...
48
            ->method('compare');
49
50
        $this
51
            ->fromProperty
52
            ->expects(self::any())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BetterReflection\R...tion\ReflectionProperty. ( Ignorable by Annotation )

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

52
            ->/** @scrutinizer ignore-call */ 
53
              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...
53
            ->method('isPublic')
54
            ->willReturn(false);
55
56
        self::assertEquals(
57
            Changes::new(),
58
            $this->changed->compare($this->fromProperty, $this->toProperty)
59
        );
60
    }
61
62
    public function testChecksPublicProperty() : void
63
    {
64
        $changes = Changes::fromArray([Change::changed(uniqid('potato', true), true)]);
65
66
        $this
67
            ->check
68
            ->expects(self::atLeastOnce())
69
            ->method('compare')
70
            ->with($this->fromProperty, $this->toProperty)
71
            ->willReturn($changes);
72
73
        $this
74
            ->fromProperty
75
            ->expects(self::any())
76
            ->method('isPublic')
77
            ->willReturn(true);
78
79
        self::assertEquals(
80
            $changes,
81
            $this->changed->compare($this->fromProperty, $this->toProperty)
82
        );
83
    }
84
}
85