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

OpenClassChangedTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testWillNotCheckOpenClass() 0 14 1
A setUp() 0 8 1
A testWillCheckFinalClass() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\ClassBased;
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\ClassBased\ClassBased;
12
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\FinalClassChanged;
13
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\OpenClassChanged;
14
use Roave\BetterReflection\Reflection\ReflectionClass;
15
use function uniqid;
16
17
/**
18
 * @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\OpenClassChanged
19
 */
20
final class OpenClassChangedTest extends TestCase
21
{
22
    /** @var ClassBased|MockObject */
23
    private $check;
24
25
    /** @var FinalClassChanged */
26
    private $openClassChanged;
27
28
    /** @var ReflectionClass|MockObject */
29
    private $fromClass;
30
31
    /** @var ReflectionClass|MockObject */
32
    private $toClass;
33
34
    protected function setUp() : void
35
    {
36
        parent::setUp();
37
38
        $this->check            = $this->createMock(ClassBased::class);
39
        $this->openClassChanged = new OpenClassChanged($this->check);
0 ignored issues
show
Documentation Bug introduced by
It seems like new Roave\ApiCompare\Com...ssChanged($this->check) of type Roave\ApiCompare\Compara...sBased\OpenClassChanged is incompatible with the declared type Roave\ApiCompare\Compara...Based\FinalClassChanged of property $openClassChanged.

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->fromClass        = $this->createMock(ReflectionClass::class);
41
        $this->toClass          = $this->createMock(ReflectionClass::class);
42
    }
43
44
    public function testWillCheckFinalClass() : void
45
    {
46
        $changes = Changes::fromArray([Change::added(uniqid('carrot', true), true)]);
47
48
        $this
49
            ->fromClass
50
            ->expects(self::any())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BetterReflection\Reflection\ReflectionClass. ( Ignorable by Annotation )

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

50
            ->/** @scrutinizer ignore-call */ 
51
              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...
51
            ->method('isFinal')
52
            ->willReturn(false);
53
54
        $this
55
            ->check
56
            ->expects(self::atLeastOnce())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\ApiCompare\Compara...y\ClassBased\ClassBased. ( Ignorable by Annotation )

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

56
            ->/** @scrutinizer ignore-call */ 
57
              expects(self::atLeastOnce())

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...
57
            ->method('compare')
58
            ->with($this->fromClass, $this->toClass)
59
            ->willReturn($changes);
60
61
        self::assertEquals($changes, $this->openClassChanged->compare($this->fromClass, $this->toClass));
62
    }
63
64
    public function testWillNotCheckOpenClass() : void
65
    {
66
        $this
67
            ->fromClass
68
            ->expects(self::any())
69
            ->method('isFinal')
70
            ->willReturn(true);
71
72
        $this
73
            ->check
74
            ->expects(self::never())
75
            ->method('compare');
76
77
        self::assertEquals(Changes::new(), $this->openClassChanged->compare($this->fromClass, $this->toClass));
78
    }
79
}
80