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

SkipPropertyBasedErrorsTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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

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