Completed
Push — master ( 68752c...dbd366 )
by Eric
28:16 queued 13:00
created

GridViewSubscriberTest::testViewWithoutGrid()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 18

Duplication

Lines 24
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 24
loc 24
rs 8.9713
cc 1
eloc 18
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 Lug\Component\Resource\Model\ResourceInterface;
23
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
24
use Symfony\Component\Form\FormInterface;
25
use Symfony\Component\Form\FormRendererInterface;
26
use Symfony\Component\Form\FormView;
27
28
/**
29
 * @author GeLo <[email protected]>
30
 */
31
class GridViewSubscriberTest extends \PHPUnit_Framework_TestCase
32
{
33
    /**
34
     * @var GridViewSubscriber
35
     */
36
    private $subscriber;
37
38
    /**
39
     * @var \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface
40
     */
41
    private $parameterResolver;
42
43
    /**
44
     * @var \PHPUnit_Framework_MockObject_MockObject|FormFactoryInterface
45
     */
46
    private $formFactory;
47
48
    /**
49
     * @var \PHPUnit_Framework_MockObject_MockObject|FormRendererInterface
50
     */
51
    private $formRenderer;
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    protected function setUp()
57
    {
58
        $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...
59
        $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...
60
        $this->formRenderer = $this->createFormRendererMock();
61
62
        $this->subscriber = new GridViewSubscriber($this->parameterResolver, $this->formFactory, $this->formRenderer);
63
    }
64
65
    public function testInheritance()
66
    {
67
        $this->assertInstanceOf(EventSubscriberInterface::class, $this->subscriber);
68
    }
69
70 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...
71
    {
72
        $this->assertSame(
73
            [RestEvents::VIEW => [
74
                ['onApi', -2000],
75
                ['onView', -1000],
76
            ]],
77
            $this->subscriber->getSubscribedEvents()
78
        );
79
    }
80
81 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...
82
    {
83
        $this->parameterResolver
84
            ->expects($this->once())
85
            ->method('resolveApi')
86
            ->will($this->returnValue(false));
87
88
        $event = $this->createViewEventMock();
89
        $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...
90
            ->expects($this->never())
91
            ->method('getView');
92
93
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 88 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...
94
    }
95
96 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...
97
    {
98
        $this->parameterResolver
99
            ->expects($this->once())
100
            ->method('resolveApi')
101
            ->will($this->returnValue(true));
102
103
        $event = $this->createViewEventMock();
104
        $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...
105
            ->expects($this->once())
106
            ->method('getView')
107
            ->will($this->returnValue($view = $this->createViewMock()));
108
109
        $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...
110
            ->expects($this->once())
111
            ->method('getData')
112
            ->will($this->returnValue('data'));
113
114
        $view
115
            ->expects($this->never())
116
            ->method('setData');
117
118
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 103 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...
119
    }
120
121 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...
122
    {
123
        $this->parameterResolver
124
            ->expects($this->once())
125
            ->method('resolveApi')
126
            ->will($this->returnValue(true));
127
128
        $event = $this->createViewEventMock();
129
        $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...
130
            ->expects($this->once())
131
            ->method('getView')
132
            ->will($this->returnValue($view = $this->createViewMock()));
133
134
        $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...
135
            ->expects($this->once())
136
            ->method('getData')
137
            ->will($this->returnValue(['grid' => $gridView = $this->createGridViewMock()]));
138
139
        $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...
140
            ->expects($this->once())
141
            ->method('getDataSource')
142
            ->will($this->returnValue($dataSource = 'data_source'));
143
144
        $view
145
            ->expects($this->once())
146
            ->method('setData')
147
            ->with($this->identicalTo($dataSource));
148
149
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 128 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...
150
    }
151
152 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...
153
    {
154
        $this->parameterResolver
155
            ->expects($this->once())
156
            ->method('resolveApi')
157
            ->will($this->returnValue(true));
158
159
        $event = $this->createViewEventMock();
160
        $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...
161
            ->expects($this->never())
162
            ->method('getView');
163
164
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 159 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...
165
    }
166
167 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...
168
    {
169
        $this->parameterResolver
170
            ->expects($this->once())
171
            ->method('resolveApi')
172
            ->will($this->returnValue(false));
173
174
        $event = $this->createViewEventMock();
175
        $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...
176
            ->expects($this->once())
177
            ->method('getView')
178
            ->will($this->returnValue($view = $this->createViewMock()));
179
180
        $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...
181
            ->expects($this->once())
182
            ->method('getData')
183
            ->will($this->returnValue('data'));
184
185
        $view
186
            ->expects($this->never())
187
            ->method('setData');
188
189
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 174 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...
190
    }
191
192
    public function testViewWithoutBatchForm()
193
    {
194
        $this->parameterResolver
195
            ->expects($this->once())
196
            ->method('resolveApi')
197
            ->will($this->returnValue(false));
198
199
        $event = $this->createViewEventMock();
200
        $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...
201
            ->expects($this->once())
202
            ->method('getView')
203
            ->will($this->returnValue($view = $this->createViewMock()));
204
205
        $event
206
            ->expects($this->once())
207
            ->method('getResource')
208
            ->will($this->returnValue($resource = $this->createResourceMock()));
209
210
        $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...
211
            ->expects($this->once())
212
            ->method('getData')
213
            ->will($this->returnValue(['grid' => $gridView = $this->createGridViewMock()]));
214
215
        $this->formFactory
216
            ->expects($this->once())
217
            ->method('create')
218
            ->with(
219
                $this->identicalTo($resource),
220
                $this->identicalTo(GridBatchType::class),
221
                $this->isNull(),
222
                $this->identicalTo(['grid' => $gridView])
223
            )
224
            ->will($this->returnValue($batchForm = $this->createFormMock()));
225
226
        $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...
227
            ->expects($this->once())
228
            ->method('createView')
229
            ->will($this->returnValue($batchFormView = $this->createFormViewMock()));
230
231
        $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...
232
            ->expects($this->once())
233
            ->method('setBatchForm')
234
            ->with($this->identicalTo($batchFormView));
235
236
        $view
237
            ->expects($this->once())
238
            ->method('setTemplateVar')
239
            ->with($this->identicalTo('grid'))
240
            ->will($this->returnSelf());
241
242
        $view
243
            ->expects($this->once())
244
            ->method('setData')
245
            ->with($this->identicalTo($gridView));
246
247
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 199 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...
248
    }
249
250
    public function testViewWithBatchForm()
251
    {
252
        $this->parameterResolver
253
            ->expects($this->once())
254
            ->method('resolveApi')
255
            ->will($this->returnValue(false));
256
257
        $event = $this->createViewEventMock();
258
        $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...
259
            ->expects($this->once())
260
            ->method('getView')
261
            ->will($this->returnValue($view = $this->createViewMock()));
262
263
        $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...
264
            ->expects($this->once())
265
            ->method('getData')
266
            ->will($this->returnValue([
267
                'grid'       => $gridView = $this->createGridViewMock(),
268
                'batch_form' => $batchForm = $this->createFormMock(),
269
            ]));
270
271
        $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...
272
            ->expects($this->once())
273
            ->method('createView')
274
            ->will($this->returnValue($batchFormView = $this->createFormViewMock()));
275
276
        $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...
277
            ->expects($this->once())
278
            ->method('setBatchForm')
279
            ->with($this->identicalTo($batchFormView));
280
281
        $view
282
            ->expects($this->once())
283
            ->method('setTemplateVar')
284
            ->with($this->identicalTo('grid'))
285
            ->will($this->returnSelf());
286
287
        $view
288
            ->expects($this->once())
289
            ->method('setData')
290
            ->with($this->identicalTo($gridView));
291
292
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 257 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...
293
    }
294
295
    public function testViewFormThemes()
296
    {
297
        $this->parameterResolver
298
            ->expects($this->once())
299
            ->method('resolveApi')
300
            ->will($this->returnValue(false));
301
302
        $this->parameterResolver
303
            ->expects($this->once())
304
            ->method('resolveThemes')
305
            ->will($this->returnValue($themes = ['theme']));
306
307
        $event = $this->createViewEventMock();
308
        $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...
309
            ->expects($this->once())
310
            ->method('getView')
311
            ->will($this->returnValue($view = $this->createViewMock()));
312
313
        $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...
314
            ->expects($this->once())
315
            ->method('getData')
316
            ->will($this->returnValue([
317
                'grid'       => $gridView = $this->createGridViewMock(),
318
                'batch_form' => $batchForm = $this->createFormMock(),
319
            ]));
320
321
        $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...
322
            ->expects($this->once())
323
            ->method('createView')
324
            ->will($this->returnValue($batchFormView = $this->createFormViewMock()));
325
326
        $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...
327
            ->expects($this->once())
328
            ->method('setBatchForm')
329
            ->with($this->identicalTo($batchFormView));
330
331
        $gridView
332
            ->expects($this->once())
333
            ->method('getForm')
334
            ->will($this->returnValue($formView = $this->createFormViewMock()));
335
336
        $gridView
337
            ->expects($this->exactly(2))
338
            ->method('getBatchForm')
339
            ->willReturnOnConsecutiveCalls(null, $batchFormView);
340
341
        $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...
342
            ->expects($this->exactly(2))
343
            ->method('setTheme')
344
            ->withConsecutive(
345
                [$formView, $themes],
346
                [$batchFormView, $themes]
347
            );
348
349
        $view
350
            ->expects($this->once())
351
            ->method('setTemplateVar')
352
            ->with($this->identicalTo('grid'))
353
            ->will($this->returnSelf());
354
355
        $view
356
            ->expects($this->once())
357
            ->method('setData')
358
            ->with($this->identicalTo($gridView));
359
360
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 307 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...
361
    }
362
363
    /**
364
     * @return \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface
365
     */
366
    private function createParameterResolverMock()
367
    {
368
        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...
369
    }
370
371
    /**
372
     * @return \PHPUnit_Framework_MockObject_MockObject|FormFactoryInterface
373
     */
374
    private function createFormFactoryMock()
375
    {
376
        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...
377
    }
378
379
    /**
380
     * @return \PHPUnit_Framework_MockObject_MockObject|FormRendererInterface
381
     */
382
    private function createFormRendererMock()
383
    {
384
        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...
385
    }
386
387
    /**
388
     * @return \PHPUnit_Framework_MockObject_MockObject|ViewEvent
389
     */
390
    private function createViewEventMock()
391
    {
392
        return $this->getMockBuilder(ViewEvent::class)
393
            ->disableOriginalConstructor()
394
            ->getMock();
395
    }
396
397
    /**
398
     * @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
399
     */
400
    private function createResourceMock()
401
    {
402
        return $this->getMock(ResourceInterface::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...
403
    }
404
405
    /**
406
     * @return \PHPUnit_Framework_MockObject_MockObject|View
407
     */
408
    private function createViewMock()
409
    {
410
        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...
411
    }
412
413
    /**
414
     * @return \PHPUnit_Framework_MockObject_MockObject|FormInterface
415
     */
416
    private function createFormMock()
417
    {
418
        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...
419
    }
420
421
    /**
422
     * @return \PHPUnit_Framework_MockObject_MockObject|FormView
423
     */
424
    private function createFormViewMock()
425
    {
426
        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...
427
    }
428
429
    /**
430
     * @return \PHPUnit_Framework_MockObject_MockObject|GridViewInterface
431
     */
432
    private function createGridViewMock()
433
    {
434
        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...
435
    }
436
}
437