GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#31)
by Rodrigue
01:53
created

ArgumentOrganiserTest::testOrganiseArguments()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 28
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the StepArgumentInjectorBehatExtension project.
5
 *
6
 * (c) Rodrigue Villetard <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Gorghoa\StepArgumentInjectorBehatExtension\Argument;
13
14
use Doctrine\Common\Annotations\Reader;
15
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument;
16
use Prophecy\Prophecy\ObjectProphecy;
17
use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser;
18
19
/**
20
 * @author Vincent Chalamon <[email protected]>
21
 * @author Rodrigue Villetard <[email protected]>
22
 */
23
class ArgumentOrganiserTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @var ArgumentOrganiser
27
     */
28
    private $organiser;
29
30
    /**
31
     * @var ObjectProphecy|ArgumentOrganiser
32
     */
33
    private $organiserMock;
34
35
    /**
36
     * @var ObjectProphecy
37
     */
38
    private $initializerMock;
0 ignored issues
show
Unused Code introduced by
The property $initializerMock is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
39
40
    /**
41
     * @var ObjectProphecy|\ReflectionMethod
42
     */
43
    private $functionMock;
44
45
    /**
46
     * @var ObjectProphecy|Reader
47
     */
48
    private $readerMock;
49
50
    /**
51
     * @var StepArgumentHolder
52
     */
53
    private $holderMock;
54
55
    protected function setUp()
56
    {
57
        $this->organiserMock = $this->prophesize(BehatArgumentOrganiser::class);
58
        $this->functionMock = $this->prophesize(\ReflectionMethod::class);
59
        $this->readerMock = $this->prophesize(Reader::class);
60
        $this->holderMock = $this->prophesize(StepArgumentHolder::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->prophesize(\Gorgh...pArgumentHolder::class) of type object<Prophecy\Prophecy\ObjectProphecy> is incompatible with the declared type object<Gorghoa\StepArgum...ent\StepArgumentHolder> of property $holderMock.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
61
62
        $this->organiser = new ArgumentOrganiser(
63
            $this->organiserMock->reveal(),
64
            [$this->holderMock->reveal()],
65
            $this->readerMock->reveal()
66
        );
67
    }
68
69
    /**
70
     * @return ObjectProphecy
71
     */
72
    private function annotationMockFactory()
73
    {
74
        return $this->prophesize(StepInjectorArgument::class);
75
    }
76
77
    public function testOrganiseArguments()
78
    {
79
        $this->functionMock->getParameters()->willReturn([
80
            (object) ['name' => 'scenarioBanana'], // argument with injector annotation and **a service hold** value
81
            (object) ['name' => 'gorilla'], // argument with injector annotation but **no service hold** value
82
            (object) ['name' => 'foo'], // argument not handled by this extension
83
        ])->shouldBeCalledTimes(1);
84
85
        $annot1 = $this->annotationMockFactory();
86
        $annot1->getArgument()->willReturn('scenarioBanana')->shouldBeCalledTimes(1);
87
        $annot1->reveal();
88
89
        $annot2 = $this->annotationMockFactory();
90
        $annot2->getArgument()->willReturn('gorilla')->shouldBeCalledTimes(1);
91
        $annot2->reveal();
92
93
        $this->readerMock->getMethodAnnotations($this->functionMock->reveal())->willReturn([
94
            $annot1,
95
            $annot2,
96
        ])->shouldBeCalledTimes(1);
97
98
        $this->holderMock->doesHandleStepArgument($annot1)->willReturn(true);
0 ignored issues
show
Documentation introduced by
$annot1 is of type object<Prophecy\Prophecy\ObjectProphecy>, but the function expects a object<Gorghoa\StepArgum...n\StepInjectorArgument>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
The method willReturn cannot be called on $this->holderMock->doesH...leStepArgument($annot1) (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
99
        $this->holderMock->doesHandleStepArgument($annot2)->willReturn(false);
0 ignored issues
show
Documentation introduced by
$annot2 is of type object<Prophecy\Prophecy\ObjectProphecy>, but the function expects a object<Gorghoa\StepArgum...n\StepInjectorArgument>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Bug introduced by
The method willReturn cannot be called on $this->holderMock->doesH...leStepArgument($annot2) (of type boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
100
101
        $this->holderMock->getStepArgumentValueFor($annot1)->willReturn('yammyBanana')->shouldBeCalledTimes(1);
0 ignored issues
show
Documentation introduced by
$annot1 is of type object<Prophecy\Prophecy\ObjectProphecy>, but the function expects a object<Gorghoa\StepArgum...n\StepInjectorArgument>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
102
        $this->holderMock->getStepArgumentValueFor($annot2)->shouldNotBeCalled();
0 ignored issues
show
Documentation introduced by
$annot2 is of type object<Prophecy\Prophecy\ObjectProphecy>, but the function expects a object<Gorghoa\StepArgum...n\StepInjectorArgument>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
103
104
        $this->holderMock->getStepArgumentValueFor($annot2);
0 ignored issues
show
Documentation introduced by
$annot2 is of type object<Prophecy\Prophecy\ObjectProphecy>, but the function expects a object<Gorghoa\StepArgum...n\StepInjectorArgument>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
105
106
        $this->organiserMock->organiseArguments($this->functionMock->reveal(), [
0 ignored issues
show
Bug introduced by
The method organiseArguments does only exist in Gorghoa\StepArgumentInje...ument\ArgumentOrganiser, but not in Prophecy\Prophecy\ObjectProphecy.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
107
            0 => 'scenarioBanana',
108
            1 => 'gorilla',
109
            'scenarioBanana' => 'yammyBanana',
110
            2 => 'yammyBanana',
111
        ])->shouldBeCalledTimes(1);
112
113
        $this->organiser->organiseArguments($this->functionMock->reveal(), ['scenarioBanana', 'gorilla']);
114
    }
115
}
116