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

testSkipsNonPublicConstant()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 12
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\ClassConstantBased;
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\ClassConstantBased\ClassConstantBased;
12
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassConstantBased\OnlyPublicClassConstantChanged;
13
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
14
use function uniqid;
15
16
/**
17
 * @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassConstantBased\OnlyPublicClassConstantChanged
18
 */
19
final class OnlyPublicClassConstantChangedTest extends TestCase
20
{
21
    /** @var ClassConstantBased|MockObject */
22
    private $check;
23
24
    /** @var ReflectionClassConstant|MockObject */
25
    private $fromConstant;
26
27
    /** @var ReflectionClassConstant|MockObject */
28
    private $toConstant;
29
30
    /** @var OnlyPublicClassConstantChanged */
31
    private $changed;
32
33
    protected function setUp() : void
34
    {
35
        parent::setUp();
36
37
        $this->check        = $this->createMock(ClassConstantBased::class);
38
        $this->changed      = new OnlyPublicClassConstantChanged($this->check);
39
        $this->fromConstant = $this->createMock(ReflectionClassConstant::class);
40
        $this->toConstant   = $this->createMock(ReflectionClassConstant::class);
41
    }
42
43
    public function testSkipsNonPublicConstant() : 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...ased\ClassConstantBased. ( 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
            ->fromConstant
52
            ->expects(self::any())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BetterReflection\R...ReflectionClassConstant. ( 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->fromConstant, $this->toConstant)
59
        );
60
    }
61
62
    public function testChecksPublicConstant() : 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->fromConstant, $this->toConstant)
71
            ->willReturn($changes);
72
73
        $this
74
            ->fromConstant
75
            ->expects(self::any())
76
            ->method('isPublic')
77
            ->willReturn(true);
78
79
        self::assertEquals(
80
            $changes,
81
            $this->changed->compare($this->fromConstant, $this->toConstant)
82
        );
83
    }
84
}
85