Completed
Push — master ( dbe8ee...3d47db )
by Eric
8s
created

createParameterResolverMock()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\ResourceBundle\Tests\Rest\View;
13
14
use FOS\RestBundle\View\View;
15
use Lug\Bundle\GridBundle\Form\Type\Batch\GridBatchType;
16
use Lug\Bundle\GridBundle\View\GridViewInterface;
17
use Lug\Bundle\ResourceBundle\Form\FormFactoryInterface;
18
use Lug\Bundle\ResourceBundle\Rest\RestEvents;
19
use Lug\Bundle\ResourceBundle\Rest\View\EventSubscriber\GridViewSubscriber;
20
use Lug\Bundle\ResourceBundle\Rest\View\ViewEvent;
21
use Lug\Bundle\ResourceBundle\Routing\ParameterResolverInterface;
22
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
23
use Symfony\Component\Form\FormInterface;
24
use Symfony\Component\Form\FormRendererInterface;
25
use Symfony\Component\Form\FormView;
26
27
/**
28
 * @author GeLo <[email protected]>
29
 */
30
class GridViewSubscriberTest extends \PHPUnit_Framework_TestCase
31
{
32
    /**
33
     * @var GridViewSubscriber
34
     */
35
    private $subscriber;
36
37
    /**
38
     * @var \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface
39
     */
40
    private $parameterResolver;
41
42
    /**
43
     * @var \PHPUnit_Framework_MockObject_MockObject|FormFactoryInterface
44
     */
45
    private $formFactory;
46
47
    /**
48
     * @var \PHPUnit_Framework_MockObject_MockObject|FormRendererInterface
49
     */
50
    private $formRenderer;
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    protected function setUp()
56
    {
57
        $this->parameterResolver = $this->createParameterResolverMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createParameterResolverMock() can also be of type object<Lug\Bundle\Resour...meterResolverInterface>. However, the property $parameterResolver is declared as type object<PHPUnit_Framework_MockObject_MockObject>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
58
        $this->formFactory = $this->createFormFactoryMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createFormFactoryMock() can also be of type object<Lug\Bundle\Resour...m\FormFactoryInterface>. However, the property $formFactory is declared as type object<PHPUnit_Framework_MockObject_MockObject>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
59
        $this->formRenderer = $this->createFormRendererMock();
60
61
        $this->subscriber = new GridViewSubscriber($this->parameterResolver, $this->formFactory, $this->formRenderer);
62
    }
63
64
    public function testInheritance()
65
    {
66
        $this->assertInstanceOf(EventSubscriberInterface::class, $this->subscriber);
67
    }
68
69 View Code Duplication
    public function testSubscribedEvents()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        $this->assertSame(
72
            [RestEvents::VIEW => [
73
                ['onApi', -2000],
74
                ['onView', -1000],
75
            ]],
76
            $this->subscriber->getSubscribedEvents()
77
        );
78
    }
79
80 View Code Duplication
    public function testApiWithoutApi()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        $this->parameterResolver
83
            ->expects($this->once())
84
            ->method('resolveApi')
85
            ->will($this->returnValue(false));
86
87
        $event = $this->createViewEventMock();
88
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
89
            ->expects($this->never())
90
            ->method('getView');
91
92
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 87 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...ViewSubscriber::onApi() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
93
    }
94
95 View Code Duplication
    public function testApiWithoutGrid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $this->parameterResolver
98
            ->expects($this->once())
99
            ->method('resolveApi')
100
            ->will($this->returnValue(true));
101
102
        $event = $this->createViewEventMock();
103
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
104
            ->expects($this->once())
105
            ->method('getView')
106
            ->will($this->returnValue($view = $this->createViewMock()));
107
108
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in FOS\RestBundle\View\View.

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...
109
            ->expects($this->once())
110
            ->method('getData')
111
            ->will($this->returnValue('data'));
112
113
        $view
114
            ->expects($this->never())
115
            ->method('setData');
116
117
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 102 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...ViewSubscriber::onApi() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
118
    }
119
120 View Code Duplication
    public function testApiWithGrid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
121
    {
122
        $this->parameterResolver
123
            ->expects($this->once())
124
            ->method('resolveApi')
125
            ->will($this->returnValue(true));
126
127
        $event = $this->createViewEventMock();
128
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
129
            ->expects($this->once())
130
            ->method('getView')
131
            ->will($this->returnValue($view = $this->createViewMock()));
132
133
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in FOS\RestBundle\View\View.

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...
134
            ->expects($this->once())
135
            ->method('getData')
136
            ->will($this->returnValue(['grid' => $gridView = $this->createGridViewMock()]));
137
138
        $gridView
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

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...
139
            ->expects($this->once())
140
            ->method('getDataSource')
141
            ->will($this->returnValue($dataSource = 'data_source'));
142
143
        $view
144
            ->expects($this->once())
145
            ->method('setData')
146
            ->with($this->identicalTo($dataSource));
147
148
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 127 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...ViewSubscriber::onApi() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
149
    }
150
151 View Code Duplication
    public function testViewWithApi()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
152
    {
153
        $this->parameterResolver
154
            ->expects($this->once())
155
            ->method('resolveApi')
156
            ->will($this->returnValue(true));
157
158
        $event = $this->createViewEventMock();
159
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
160
            ->expects($this->never())
161
            ->method('getView');
162
163
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 158 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...iewSubscriber::onView() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
164
    }
165
166 View Code Duplication
    public function testViewWithoutGrid()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
167
    {
168
        $this->parameterResolver
169
            ->expects($this->once())
170
            ->method('resolveApi')
171
            ->will($this->returnValue(false));
172
173
        $event = $this->createViewEventMock();
174
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
175
            ->expects($this->once())
176
            ->method('getView')
177
            ->will($this->returnValue($view = $this->createViewMock()));
178
179
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in FOS\RestBundle\View\View.

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...
180
            ->expects($this->once())
181
            ->method('getData')
182
            ->will($this->returnValue('data'));
183
184
        $view
185
            ->expects($this->never())
186
            ->method('setData');
187
188
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 173 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...iewSubscriber::onView() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
189
    }
190
191
    public function testViewWithoutBatchForm()
192
    {
193
        $this->parameterResolver
194
            ->expects($this->once())
195
            ->method('resolveApi')
196
            ->will($this->returnValue(false));
197
198
        $event = $this->createViewEventMock();
199
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
200
            ->expects($this->once())
201
            ->method('getView')
202
            ->will($this->returnValue($view = $this->createViewMock()));
203
204
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in FOS\RestBundle\View\View.

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...
205
            ->expects($this->once())
206
            ->method('getData')
207
            ->will($this->returnValue(['grid' => $gridView = $this->createGridViewMock()]));
208
209
        $this->formFactory
210
            ->expects($this->once())
211
            ->method('create')
212
            ->with(
213
                $this->identicalTo(GridBatchType::class),
214
                $this->isNull(),
215
                $this->identicalTo(['grid' => $gridView])
216
            )
217
            ->will($this->returnValue($batchForm = $this->createFormMock()));
218
219
        $batchForm
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Form\FormInterface.

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...
220
            ->expects($this->once())
221
            ->method('createView')
222
            ->will($this->returnValue($batchFormView = $this->createFormViewMock()));
223
224
        $gridView
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

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...
225
            ->expects($this->once())
226
            ->method('setBatchForm')
227
            ->with($this->identicalTo($batchFormView));
228
229
        $view
230
            ->expects($this->once())
231
            ->method('setTemplateVar')
232
            ->with($this->identicalTo('grid'))
233
            ->will($this->returnSelf());
234
235
        $view
236
            ->expects($this->once())
237
            ->method('setData')
238
            ->with($this->identicalTo($gridView));
239
240
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 198 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...iewSubscriber::onView() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
241
    }
242
243
    public function testViewWithBatchForm()
244
    {
245
        $this->parameterResolver
246
            ->expects($this->once())
247
            ->method('resolveApi')
248
            ->will($this->returnValue(false));
249
250
        $event = $this->createViewEventMock();
251
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
252
            ->expects($this->once())
253
            ->method('getView')
254
            ->will($this->returnValue($view = $this->createViewMock()));
255
256
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in FOS\RestBundle\View\View.

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...
257
            ->expects($this->once())
258
            ->method('getData')
259
            ->will($this->returnValue([
260
                'grid'       => $gridView = $this->createGridViewMock(),
261
                'batch_form' => $batchForm = $this->createFormMock(),
262
            ]));
263
264
        $batchForm
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Form\FormInterface.

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...
265
            ->expects($this->once())
266
            ->method('createView')
267
            ->will($this->returnValue($batchFormView = $this->createFormViewMock()));
268
269
        $gridView
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

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...
270
            ->expects($this->once())
271
            ->method('setBatchForm')
272
            ->with($this->identicalTo($batchFormView));
273
274
        $view
275
            ->expects($this->once())
276
            ->method('setTemplateVar')
277
            ->with($this->identicalTo('grid'))
278
            ->will($this->returnSelf());
279
280
        $view
281
            ->expects($this->once())
282
            ->method('setData')
283
            ->with($this->identicalTo($gridView));
284
285
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 250 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...iewSubscriber::onView() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
286
    }
287
288
    public function testViewFormThemes()
289
    {
290
        $this->parameterResolver
291
            ->expects($this->once())
292
            ->method('resolveApi')
293
            ->will($this->returnValue(false));
294
295
        $this->parameterResolver
296
            ->expects($this->once())
297
            ->method('resolveThemes')
298
            ->will($this->returnValue($themes = ['theme']));
299
300
        $event = $this->createViewEventMock();
301
        $event
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\ResourceBundle\Rest\View\ViewEvent.

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...
302
            ->expects($this->once())
303
            ->method('getView')
304
            ->will($this->returnValue($view = $this->createViewMock()));
305
306
        $view
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in FOS\RestBundle\View\View.

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...
307
            ->expects($this->once())
308
            ->method('getData')
309
            ->will($this->returnValue([
310
                'grid'       => $gridView = $this->createGridViewMock(),
311
                'batch_form' => $batchForm = $this->createFormMock(),
312
            ]));
313
314
        $batchForm
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Form\FormInterface.

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...
315
            ->expects($this->once())
316
            ->method('createView')
317
            ->will($this->returnValue($batchFormView = $this->createFormViewMock()));
318
319
        $gridView
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Bundle\GridBundle\View\GridViewInterface.

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...
320
            ->expects($this->once())
321
            ->method('setBatchForm')
322
            ->with($this->identicalTo($batchFormView));
323
324
        $gridView
325
            ->expects($this->once())
326
            ->method('getForm')
327
            ->will($this->returnValue($formView = $this->createFormViewMock()));
328
329
        $gridView
330
            ->expects($this->exactly(2))
331
            ->method('getBatchForm')
332
            ->willReturnOnConsecutiveCalls(null, $batchFormView);
333
334
        $this->formRenderer
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Form\FormRendererInterface.

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...
335
            ->expects($this->exactly(2))
336
            ->method('setTheme')
337
            ->withConsecutive(
338
                [$formView, $themes],
339
                [$batchFormView, $themes]
340
            );
341
342
        $view
343
            ->expects($this->once())
344
            ->method('setTemplateVar')
345
            ->with($this->identicalTo('grid'))
346
            ->will($this->returnSelf());
347
348
        $view
349
            ->expects($this->once())
350
            ->method('setData')
351
            ->with($this->identicalTo($gridView));
352
353
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 300 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...iewSubscriber::onView() does only seem to accept object<Lug\Bundle\Resour...le\Rest\View\ViewEvent>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
354
    }
355
356
    /**
357
     * @return \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface
358
     */
359
    private function createParameterResolverMock()
360
    {
361
        return $this->getMock(ParameterResolverInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
362
    }
363
364
    /**
365
     * @return \PHPUnit_Framework_MockObject_MockObject|FormFactoryInterface
366
     */
367
    private function createFormFactoryMock()
368
    {
369
        return $this->getMock(FormFactoryInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
370
    }
371
372
    /**
373
     * @return \PHPUnit_Framework_MockObject_MockObject|FormRendererInterface
374
     */
375
    private function createFormRendererMock()
376
    {
377
        return $this->getMock(FormRendererInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
378
    }
379
380
    /**
381
     * @return \PHPUnit_Framework_MockObject_MockObject|ViewEvent
382
     */
383
    private function createViewEventMock()
384
    {
385
        return $this->getMockBuilder(ViewEvent::class)
386
            ->disableOriginalConstructor()
387
            ->getMock();
388
    }
389
390
    /**
391
     * @return \PHPUnit_Framework_MockObject_MockObject|View
392
     */
393
    private function createViewMock()
394
    {
395
        return $this->getMock(View::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
396
    }
397
398
    /**
399
     * @return \PHPUnit_Framework_MockObject_MockObject|FormInterface
400
     */
401
    private function createFormMock()
402
    {
403
        return $this->getMock(FormInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
404
    }
405
406
    /**
407
     * @return \PHPUnit_Framework_MockObject_MockObject|FormView
408
     */
409
    private function createFormViewMock()
410
    {
411
        return $this->getMock(FormView::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
412
    }
413
414
    /**
415
     * @return \PHPUnit_Framework_MockObject_MockObject|GridViewInterface
416
     */
417
    private function createGridViewMock()
418
    {
419
        return $this->getMock(GridViewInterface::class);
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit_Framework_TestCase::getMock() has been deprecated with message: Method deprecated since Release 5.4.0

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
420
    }
421
}
422