Passed
Pull Request — master (#92)
by Marco
02:50
created

testWillForwardChecks()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 12
nc 1
nop 0
dl 0
loc 17
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased;
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\InterfaceBased\InterfaceBased;
13
use Roave\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased\SkipInterfaceBasedErrors;
14
use Roave\BetterReflection\Reflection\ReflectionClass;
15
16
/**
17
 * @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\InterfaceBased\SkipInterfaceBasedErrors
18
 */
19
final class SkipInterfaceBasedErrorsTest extends TestCase
20
{
21
    /** @var InterfaceBased|MockObject */
22
    private $next;
23
24
    /** @var SkipInterfaceBasedErrors */
25
    private $check;
26
27
    protected function setUp() : void
28
    {
29
        $this->next  = $this->createMock(InterfaceBased::class);
30
        $this->check = new SkipInterfaceBasedErrors($this->next);
31
    }
32
33
    public function testWillForwardChecks() : void
34
    {
35
        $fromInterface   = $this->createMock(ReflectionClass::class);
36
        $toInterface     = $this->createMock(ReflectionClass::class);
37
        $expectedChanges = Changes::fromList(Change::added(
38
            uniqid('foo', true),
39
            true
40
        ));
41
42
        $this
43
            ->next
44
            ->expects(self::once())
0 ignored issues
show
Bug introduced by
The method expects() does not exist on Roave\BackwardCompatibil...aceBased\InterfaceBased. ( Ignorable by Annotation )

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

44
            ->/** @scrutinizer ignore-call */ 
45
              expects(self::once())

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...
45
            ->method('__invoke')
46
            ->with($fromInterface, $toInterface)
47
            ->willReturn($expectedChanges);
48
49
        self::assertEquals($expectedChanges, $this->check->__invoke($fromInterface, $toInterface));
50
    }
51
52
    public function testWillCollectFailures() : void
53
    {
54
        $fromInterface = $this->createMock(ReflectionClass::class);
55
        $toInterface   = $this->createMock(ReflectionClass::class);
56
        $exception     = new Exception();
57
58
        $this
59
            ->next
60
            ->expects(self::once())
61
            ->method('__invoke')
62
            ->with($fromInterface, $toInterface)
63
            ->willThrowException($exception);
64
65
        self::assertEquals(
66
            Changes::fromList(Change::skippedDueToFailure($exception)),
67
            $this->check->__invoke($fromInterface, $toInterface)
68
        );
69
    }
70
}
71