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

FinalClassChangedTest   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 setUp() 0 8 1
A testWillNotCheckOpenClass() 0 14 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\BetterReflection\Reflection\ReflectionClass;
14
15
/**
16
 * @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\FinalClassChanged
17
 */
18
final class FinalClassChangedTest extends TestCase
19
{
20
    /** @var ClassBased|MockObject */
21
    private $check;
22
23
    /** @var FinalClassChanged */
24
    private $finalClassChanged;
25
26
    /** @var ReflectionClass|MockObject */
27
    private $fromClass;
28
29
    /** @var ReflectionClass|MockObject */
30
    private $toClass;
31
32
    protected function setUp() : void
33
    {
34
        parent::setUp();
35
36
        $this->check             = $this->createMock(ClassBased::class);
37
        $this->finalClassChanged = new FinalClassChanged($this->check);
38
        $this->fromClass         = $this->createMock(ReflectionClass::class);
39
        $this->toClass           = $this->createMock(ReflectionClass::class);
40
    }
41
42
    public function testWillCheckFinalClass() : void
43
    {
44
        $changes = Changes::fromArray([Change::added(uniqid('carrot', true), true)]);
45
46
        $this
47
            ->fromClass
48
            ->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

48
            ->/** @scrutinizer ignore-call */ 
49
              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...
49
            ->method('isFinal')
50
            ->willReturn(true);
51
52
        $this
53
            ->check
54
            ->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

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