SkipClassConstantBasedErrorsTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 28
c 1
b 0
f 1
dl 0
loc 49
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testWillCollectFailures() 0 16 1
A setUp() 0 4 1
A testWillForwardChecks() 0 17 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased;
6
7
use Exception;
8
use PHPUnit\Framework\MockObject\MockObject;
9
use PHPUnit\Framework\TestCase;
10
use Roave\BackwardCompatibility\Change;
11
use Roave\BackwardCompatibility\Changes;
12
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\ClassConstantBased;
13
use Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\SkipClassConstantBasedErrors;
14
use Roave\BetterReflection\Reflection\ReflectionClassConstant;
15
use function uniqid;
16
17
/**
18
 * @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\ClassConstantBased\SkipClassConstantBasedErrors
19
 */
20
final class SkipClassConstantBasedErrorsTest extends TestCase
21
{
22
    /** @var ClassConstantBased&MockObject */
23
    private $next;
24
25
    /** @var SkipClassConstantBasedErrors */
26
    private $check;
27
28
    protected function setUp() : void
29
    {
30
        $this->next  = $this->createMock(ClassConstantBased::class);
31
        $this->check = new SkipClassConstantBasedErrors($this->next);
32
    }
33
34
    public function testWillForwardChecks() : void
35
    {
36
        $fromConstant    = $this->createMock(ReflectionClassConstant::class);
37
        $toConstant      = $this->createMock(ReflectionClassConstant::class);
38
        $expectedChanges = Changes::fromList(Change::added(
39
            uniqid('foo', true),
40
            true
41
        ));
42
43
        $this
44
            ->next
45
            ->expects(self::once())
46
            ->method('__invoke')
47
            ->with($fromConstant, $toConstant)
48
            ->willReturn($expectedChanges);
49
50
        self::assertEquals($expectedChanges, $this->check->__invoke($fromConstant, $toConstant));
51
    }
52
53
    public function testWillCollectFailures() : void
54
    {
55
        $fromConstant = $this->createMock(ReflectionClassConstant::class);
56
        $toConstant   = $this->createMock(ReflectionClassConstant::class);
57
        $exception    = new Exception();
58
59
        $this
60
            ->next
61
            ->expects(self::once())
62
            ->method('__invoke')
63
            ->with($fromConstant, $toConstant)
64
            ->willThrowException($exception);
65
66
        self::assertEquals(
67
            Changes::fromList(Change::skippedDueToFailure($exception)),
68
            $this->check->__invoke($fromConstant, $toConstant)
69
        );
70
    }
71
}
72