Completed
Pull Request — master (#38)
by Marco
02:14
created

OnlyProtectedPropertyChangedTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSkipsNonProtectedProperty() 0 16 1
A testChecksProtectedProperty() 0 20 1
A setUp() 0 8 1
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\OnlyProtectedPropertyChanged;
13
use Roave\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased\PropertyBased;
14
use Roave\BetterReflection\Reflection\ReflectionProperty;
15
use function uniqid;
16
17
/**
18
 * @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\PropertyBased\OnlyProtectedPropertyChanged
19
 */
20
final class OnlyProtectedPropertyChangedTest extends TestCase
21
{
22
    /** @var PropertyBased|MockObject */
23
    private $check;
24
25
    /** @var ReflectionProperty|MockObject */
26
    private $fromProperty;
27
28
    /** @var ReflectionProperty|MockObject */
29
    private $toProperty;
30
31
    /** @var AccessiblePropertyChanged */
32
    private $changed;
33
34
    protected function setUp() : void
35
    {
36
        parent::setUp();
37
38
        $this->check        = $this->createMock(PropertyBased::class);
39
        $this->changed      = new OnlyProtectedPropertyChanged($this->check);
0 ignored issues
show
Documentation Bug introduced by
It seems like new Roave\ApiCompare\Com...tyChanged($this->check) of type Roave\ApiCompare\Compara...rotectedPropertyChanged is incompatible with the declared type Roave\ApiCompare\Compara...cessiblePropertyChanged of property $changed.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
        $this->fromProperty = $this->createMock(ReflectionProperty::class);
41
        $this->toProperty   = $this->createMock(ReflectionProperty::class);
42
    }
43
44
    public function testSkipsNonProtectedProperty() : void
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...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

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
        $this
52
            ->fromProperty
53
            ->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

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