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

AccessiblePropertyChangedTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
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\AccessiblePropertyChanged;
12
use Roave\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased\PropertyBased;
13
use Roave\BetterReflection\Reflection\ReflectionProperty;
14
15
/**
16
 * @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased\AccessiblePropertyChanged
17
 */
18
final class AccessiblePropertyChangedTest extends TestCase
19
{
20
    /**
21
     * @var PropertyBased|MockObject
22
     */
23
    private $check;
24
25
    /**
26
     * @var ReflectionProperty|MockObject
27
     */
28
    private $fromProperty;
29
30
    /**
31
     * @var ReflectionProperty|MockObject
32
     */
33
    private $toProperty;
34
35
    /**
36
     * @var AccessiblePropertyChanged
37
     */
38
    private $accessiblePropertyChanged;
39
40
    protected function setUp() : void
41
    {
42
        parent::setUp();
43
44
        $this->check                     = $this->createMock(PropertyBased::class);
45
        $this->accessiblePropertyChanged = new AccessiblePropertyChanged($this->check);
46
        $this->fromProperty              = $this->createMock(ReflectionProperty::class);
47
        $this->toProperty                = $this->createMock(ReflectionProperty::class);
48
    }
49
50
    public function testSkipsPrivateProperty() : void
51
    {
52
        $this
53
            ->check
54
            ->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

54
            ->/** @scrutinizer ignore-call */ 
55
              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...
55
            ->method('compare');
56
57
        $this
58
            ->fromProperty
59
            ->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

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