Completed
Pull Request — master (#45)
by Eric
12:15
created

testApiWithSerializerGroups()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 33
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 8.8571
cc 1
eloc 25
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\Context\Context;
15
use FOS\RestBundle\View\View;
16
use JMS\Serializer\Exclusion\GroupsExclusionStrategy;
17
use Lug\Bundle\ResourceBundle\Rest\RestEvents;
18
use Lug\Bundle\ResourceBundle\Rest\View\EventSubscriber\ResourceViewSubscriber;
19
use Lug\Bundle\ResourceBundle\Rest\View\ViewEvent;
20
use Lug\Bundle\ResourceBundle\Routing\ParameterResolverInterface;
21
use Lug\Component\Resource\Model\ResourceInterface;
22
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
23
24
/**
25
 * @author GeLo <[email protected]>
26
 */
27
class ResourceViewSubscriberTest extends \PHPUnit_Framework_TestCase
28
{
29
    /**
30
     * @var ResourceViewSubscriber
31
     */
32
    private $subscriber;
33
34
    /**
35
     * @var \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface
36
     */
37
    private $parameterResolver;
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    protected function setUp()
43
    {
44
        $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...
45
46
        $this->subscriber = new ResourceViewSubscriber($this->parameterResolver);
47
    }
48
49
    public function testInheritance()
50
    {
51
        $this->assertInstanceOf(EventSubscriberInterface::class, $this->subscriber);
52
    }
53
54 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...
55
    {
56
        $this->assertSame(
57
            [RestEvents::VIEW => [
58
                ['onApi', -4000],
59
                ['onView', -4000],
60
            ]],
61
            $this->subscriber->getSubscribedEvents()
62
        );
63
    }
64
65 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...
66
    {
67
        $this->parameterResolver
68
            ->expects($this->once())
69
            ->method('resolveApi')
70
            ->will($this->returnValue(false));
71
72
        $event = $this->createViewEventMock();
73
        $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...
74
            ->expects($this->never())
75
            ->method('getView');
76
77
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 72 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...
78
    }
79
80
    public function testApiWithSerializerGroups()
81
    {
82
        $this->parameterResolver
83
            ->expects($this->once())
84
            ->method('resolveApi')
85
            ->will($this->returnValue(true));
86
87
        $this->parameterResolver
88
            ->expects($this->once())
89
            ->method('resolveSerializerGroups')
90
            ->will($this->returnValue($groups = ['group']));
91
92
        $this->parameterResolver
93
            ->expects($this->once())
94
            ->method('resolveSerializerNull')
95
            ->will($this->returnValue($null = true));
96
97
        $event = $this->createViewEventMock();
98
        $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...
99
            ->expects($this->once())
100
            ->method('getView')
101
            ->will($this->returnValue($view = $this->createViewMock()));
102
103
        $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...
104
            ->expects($this->exactly(2))
105
            ->method('getContext')
106
            ->will($this->returnValue($context = new Context()));
107
108
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 97 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...
109
110
        $this->assertSame($groups, $context->getGroups());
111
        $this->assertSame($null, $context->getSerializeNull());
112
    }
113
114
    public function testApiWithoutSerializerGroups()
115
    {
116
        $this->parameterResolver
117
            ->expects($this->once())
118
            ->method('resolveApi')
119
            ->will($this->returnValue(true));
120
121
        $this->parameterResolver
122
            ->expects($this->once())
123
            ->method('resolveSerializerGroups')
124
            ->will($this->returnValue([]));
125
126
        $this->parameterResolver
127
            ->expects($this->once())
128
            ->method('resolveSerializerNull')
129
            ->will($this->returnValue($null = true));
130
131
        $event = $this->createViewEventMock();
132
        $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...
133
            ->expects($this->once())
134
            ->method('getView')
135
            ->will($this->returnValue($view = $this->createViewMock()));
136
137
        $event
138
            ->expects($this->once())
139
            ->method('getResource')
140
            ->will($this->returnValue($resource = $this->createResourceMock()));
141
142
        $resource
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Lug\Component\Resource\Model\ResourceInterface.

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...
143
            ->expects($this->once())
144
            ->method('getName')
145
            ->will($this->returnValue($name = 'name'));
146
147
        $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...
148
            ->expects($this->exactly(2))
149
            ->method('getContext')
150
            ->will($this->returnValue($context = new Context()));
151
152
        $this->subscriber->onApi($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 131 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...
153
154
        $this->assertSame([GroupsExclusionStrategy::DEFAULT_GROUP, 'lug.'.$name], $context->getGroups());
155
        $this->assertSame($null, $context->getSerializeNull());
156
    }
157
158 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...
159
    {
160
        $this->parameterResolver
161
            ->expects($this->once())
162
            ->method('resolveApi')
163
            ->will($this->returnValue(true));
164
165
        $event = $this->createViewEventMock();
166
        $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...
167
            ->expects($this->never())
168
            ->method('getView');
169
170
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 165 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...
171
    }
172
173 View Code Duplication
    public function testViewWithoutTemplateVar()
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...
174
    {
175
        $this->parameterResolver
176
            ->expects($this->once())
177
            ->method('resolveApi')
178
            ->will($this->returnValue(false));
179
180
        $event = $this->createViewEventMock();
181
        $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...
182
            ->expects($this->once())
183
            ->method('getView')
184
            ->will($this->returnValue($view = $this->createViewMock()));
185
186
        $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...
187
            ->expects($this->once())
188
            ->method('getData')
189
            ->will($this->returnValue($data = new \stdClass()));
190
191
        $this->parameterResolver
192
            ->expects($this->once())
193
            ->method('resolveTemplate')
194
            ->will($this->returnValue($template = 'template'));
195
196
        $view
197
            ->expects($this->once())
198
            ->method('setTemplate')
199
            ->with($this->identicalTo($template))
200
            ->will($this->returnSelf());
201
202
        $event
203
            ->expects($this->once())
204
            ->method('getResource')
205
            ->will($this->returnValue($resource = $this->createResourceMock()));
206
207
        $view
208
            ->expects($this->once())
209
            ->method('getTemplateVar')
210
            ->will($this->returnValue(null));
211
212
        $view
213
            ->expects($this->once())
214
            ->method('setData')
215
            ->with($this->identicalTo(['data' => $data, 'resource' => $resource]));
216
217
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 180 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...
218
    }
219
220 View Code Duplication
    public function testViewWithTemplateVar()
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...
221
    {
222
        $this->parameterResolver
223
            ->expects($this->once())
224
            ->method('resolveApi')
225
            ->will($this->returnValue(false));
226
227
        $event = $this->createViewEventMock();
228
        $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...
229
            ->expects($this->once())
230
            ->method('getView')
231
            ->will($this->returnValue($view = $this->createViewMock()));
232
233
        $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...
234
            ->expects($this->once())
235
            ->method('getData')
236
            ->will($this->returnValue($data = new \stdClass()));
237
238
        $this->parameterResolver
239
            ->expects($this->once())
240
            ->method('resolveTemplate')
241
            ->will($this->returnValue($template = 'template'));
242
243
        $view
244
            ->expects($this->once())
245
            ->method('setTemplate')
246
            ->with($this->identicalTo($template))
247
            ->will($this->returnSelf());
248
249
        $event
250
            ->expects($this->once())
251
            ->method('getResource')
252
            ->will($this->returnValue($resource = $this->createResourceMock()));
253
254
        $view
255
            ->expects($this->once())
256
            ->method('getTemplateVar')
257
            ->will($this->returnValue($templateVar = 'template_var'));
258
259
        $view
260
            ->expects($this->once())
261
            ->method('setData')
262
            ->with($this->identicalTo([$templateVar => $data, 'resource' => $resource]));
263
264
        $this->subscriber->onView($event);
0 ignored issues
show
Bug introduced by
It seems like $event defined by $this->createViewEventMock() on line 227 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...
265
    }
266
267
    /**
268
     * @return \PHPUnit_Framework_MockObject_MockObject|ParameterResolverInterface
269
     */
270
    private function createParameterResolverMock()
271
    {
272
        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...
273
    }
274
275
    /**
276
     * @return \PHPUnit_Framework_MockObject_MockObject|ViewEvent
277
     */
278
    private function createViewEventMock()
279
    {
280
        return $this->getMockBuilder(ViewEvent::class)
281
            ->disableOriginalConstructor()
282
            ->getMock();
283
    }
284
285
    /**
286
     * @return \PHPUnit_Framework_MockObject_MockObject|View
287
     */
288
    private function createViewMock()
289
    {
290
        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...
291
    }
292
293
    /**
294
     * @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
295
     */
296
    private function createResourceMock()
297
    {
298
        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...
299
    }
300
}
301