Completed
Push — master ( dbd366...be31ac )
by Eric
33:25 queued 21:29
created

testResolveMaxPerPageExplicit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 11
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\Routing;
13
14
use JMS\Serializer\Exclusion\GroupsExclusionStrategy;
15
use Lug\Bundle\ResourceBundle\Routing\ParameterResolver;
16
use Lug\Component\Resource\Model\ResourceInterface;
17
use Symfony\Component\HttpFoundation\ParameterBag;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpFoundation\RequestStack;
20
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
21
use Symfony\Component\Validator\Constraint;
22
23
/**
24
 * @author GeLo <[email protected]>
25
 */
26
class ParameterResolverTest extends \PHPUnit_Framework_TestCase
27
{
28
    /**
29
     * @var ParameterResolver
30
     */
31
    private $parameterResolver;
32
33
    /**
34
     * @var \PHPUnit_Framework_MockObject_MockObject|RequestStack
35
     */
36
    private $requestStack;
37
38
    /**
39
     * @var \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface
40
     */
41
    private $propertyAccessor;
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function setUp()
47
    {
48
        $this->requestStack = $this->createRequestStackMock();
49
        $this->propertyAccessor = $this->createPropertyAccessorMock();
50
51
        $this->parameterResolver = new ParameterResolver($this->requestStack, $this->propertyAccessor);
52
    }
53
54
    public function testResolveApiWithoutRequest()
55
    {
56
        $this->assertFalse($this->parameterResolver->resolveApi());
57
    }
58
59 View Code Duplication
    public function testResolveApiWihApiRequest()
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...
60
    {
61
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
62
            ->expects($this->exactly(2))
63
            ->method('getMasterRequest')
64
            ->will($this->returnValue($request = $this->createRequestMock()));
65
66
        $request->attributes
67
            ->expects($this->once())
68
            ->method('get')
69
            ->with($this->identicalTo('_lug_api'), $this->identicalTo(false))
70
            ->will($this->returnValue(true));
71
72
        $this->assertTrue($this->parameterResolver->resolveApi());
73
    }
74
75 View Code Duplication
    public function testResolveApiWithHtmlRequest()
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...
76
    {
77
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
78
            ->expects($this->exactly(2))
79
            ->method('getMasterRequest')
80
            ->will($this->returnValue($request = $this->createRequestMock()));
81
82
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
83
            ->expects($this->once())
84
            ->method('getRequestFormat')
85
            ->will($this->returnValue('html'));
86
87
        $this->assertFalse($this->parameterResolver->resolveApi());
88
    }
89
90 View Code Duplication
    public function testResolveApiWithCustomRequest()
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...
91
    {
92
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
93
            ->expects($this->exactly(2))
94
            ->method('getMasterRequest')
95
            ->will($this->returnValue($request = $this->createRequestMock()));
96
97
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
98
            ->expects($this->once())
99
            ->method('getRequestFormat')
100
            ->will($this->returnValue('json'));
101
102
        $this->assertTrue($this->parameterResolver->resolveApi());
103
    }
104
105
    public function testResolveCriteriaWithoutRequest()
106
    {
107
        $this->assertEmpty($this->parameterResolver->resolveCriteria());
108
    }
109
110 View Code Duplication
    public function testResolveCriteriaWithDefault()
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...
111
    {
112
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
113
            ->expects($this->exactly(2))
114
            ->method('getMasterRequest')
115
            ->will($this->returnValue($request = $this->createRequestMock()));
116
117
        $request->attributes
118
            ->expects($this->once())
119
            ->method('get')
120
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo([$identifier = 'id']))
121
            ->will($this->returnValue([$identifier]));
122
123
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
124
            ->expects($this->once())
125
            ->method('get')
126
            ->with($this->identicalTo($identifier), $this->isNull())
127
            ->will($this->returnValue($value = 'value'));
128
129
        $this->assertSame([$identifier => $value], $this->parameterResolver->resolveCriteria());
130
    }
131
132 View Code Duplication
    public function testResolveCriteriaWithExplicit()
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...
133
    {
134
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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->exactly(2))
136
            ->method('getMasterRequest')
137
            ->will($this->returnValue($request = $this->createRequestMock()));
138
139
        $request->attributes
140
            ->expects($this->once())
141
            ->method('get')
142
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo(['id']))
143
            ->will($this->returnValue([$identifier = 'code']));
144
145
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
146
            ->expects($this->once())
147
            ->method('get')
148
            ->with($this->identicalTo($identifier), $this->isNull())
149
            ->will($this->returnValue($value = 'value'));
150
151
        $this->assertSame([$identifier => $value], $this->parameterResolver->resolveCriteria());
152
    }
153
154
    /**
155
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
156
     * @expectedExceptionMessage The request could not be found.
157
     */
158
    public function testResolveCriteriaMandatoryWithoutRequest()
159
    {
160
        $this->parameterResolver->resolveCriteria(true);
161
    }
162
163
    /**
164
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
165
     * @expectedExceptionMessage The criteria could not be found for the route "route".
166
     */
167 View Code Duplication
    public function testResolveCriteriaMandatoryWithoutCriteria()
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->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
170
            ->expects($this->exactly(2))
171
            ->method('getMasterRequest')
172
            ->will($this->returnValue($request = $this->createRequestMock()));
173
174
        $request->attributes
175
            ->expects($this->at(0))
176
            ->method('get')
177
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo(['id']))
178
            ->will($this->returnValue([]));
179
180
        $request->attributes
181
            ->expects($this->at(1))
182
            ->method('get')
183
            ->with($this->identicalTo('_route'), $this->isNull())
184
            ->will($this->returnValue('route'));
185
186
        $this->parameterResolver->resolveCriteria(true);
187
    }
188
189
    /**
190
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
191
     * @expectedExceptionMessage The criteria "id" could not be found for the route "route".
192
     */
193
    public function testResolveCriteriaMandatoryWithoutRequestCriteria()
194
    {
195
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
196
            ->expects($this->exactly(2))
197
            ->method('getMasterRequest')
198
            ->will($this->returnValue($request = $this->createRequestMock()));
199
200
        $request->attributes
201
            ->expects($this->at(0))
202
            ->method('get')
203
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo([$identifier = 'id']))
204
            ->will($this->returnValue([$identifier]));
205
206
        $request->attributes
207
            ->expects($this->at(1))
208
            ->method('get')
209
            ->with($this->identicalTo('_route'), $this->isNull())
210
            ->will($this->returnValue('route'));
211
212
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
213
            ->expects($this->once())
214
            ->method('get')
215
            ->with($this->identicalTo($identifier), $this->isNull())
216
            ->will($this->returnValue(null));
217
218
        $this->parameterResolver->resolveCriteria(true);
219
    }
220
221
    public function testResolveCurrentPageWithoutRequest()
222
    {
223
        $this->assertSame(1, $this->parameterResolver->resolveCurrentPage());
224
    }
225
226
    public function testResolveCurrentPageDefault()
227
    {
228
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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->exactly(2))
230
            ->method('getMasterRequest')
231
            ->will($this->returnValue($request = $this->createRequestMock()));
232
233
        $request->attributes
234
            ->expects($this->once())
235
            ->method('get')
236
            ->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo($pageParameter = 'page'))
237
            ->will($this->returnValue($pageParameter));
238
239
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
240
            ->expects($this->once())
241
            ->method('get')
242
            ->with($this->identicalTo($pageParameter), $this->identicalTo($page = 1))
243
            ->will($this->returnValue($page));
244
245
        $this->assertSame($page, $this->parameterResolver->resolveCurrentPage());
246
    }
247
248 View Code Duplication
    public function testResolveCurrentPageExplicitParameter()
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...
249
    {
250
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
251
            ->expects($this->exactly(2))
252
            ->method('getMasterRequest')
253
            ->will($this->returnValue($request = $this->createRequestMock()));
254
255
        $request->attributes
256
            ->expects($this->once())
257
            ->method('get')
258
            ->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo('page'))
259
            ->will($this->returnValue($pageParameter = 'p'));
260
261
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
262
            ->expects($this->once())
263
            ->method('get')
264
            ->with($this->identicalTo($pageParameter), $this->identicalTo($page = 1))
265
            ->will($this->returnValue($page));
266
267
        $this->assertSame($page, $this->parameterResolver->resolveCurrentPage());
268
    }
269
270 View Code Duplication
    public function testResolveCurrentPageExplicitPage()
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...
271
    {
272
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
273
            ->expects($this->exactly(2))
274
            ->method('getMasterRequest')
275
            ->will($this->returnValue($request = $this->createRequestMock()));
276
277
        $request->attributes
278
            ->expects($this->once())
279
            ->method('get')
280
            ->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo($pageParameter = 'page'))
281
            ->will($this->returnValue($pageParameter));
282
283
        $request
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\Request.

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...
284
            ->expects($this->once())
285
            ->method('get')
286
            ->with($this->identicalTo($pageParameter), $this->identicalTo(1))
287
            ->will($this->returnValue($page = 2));
288
289
        $this->assertSame($page, $this->parameterResolver->resolveCurrentPage());
290
    }
291
292 View Code Duplication
    public function testResolveFormWithoutRequest()
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...
293
    {
294
        $resource = $this->createResourceMock();
295
        $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...
296
            ->expects($this->once())
297
            ->method('getForm')
298
            ->will($this->returnValue($form = 'form'));
299
300
        $this->assertSame($form, $this->parameterResolver->resolveForm($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 294 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...Resolver::resolveForm() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
301
    }
302
303
    public function testResolveFormDefault()
304
    {
305
        $resource = $this->createResourceMock();
306
        $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...
307
            ->expects($this->once())
308
            ->method('getForm')
309
            ->will($this->returnValue($form = 'form'));
310
311
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
312
            ->expects($this->once())
313
            ->method('getMasterRequest')
314
            ->will($this->returnValue($request = $this->createRequestMock()));
315
316
        $request->attributes
317
            ->expects($this->once())
318
            ->method('get')
319
            ->with($this->identicalTo('_lug_form'), $this->identicalTo($form))
320
            ->will($this->returnValue($form));
321
322
        $this->assertSame($form, $this->parameterResolver->resolveForm($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 305 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...Resolver::resolveForm() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
323
    }
324
325 View Code Duplication
    public function testResolveFormExplicit()
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...
326
    {
327
        $resource = $this->createResourceMock();
328
        $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...
329
            ->expects($this->once())
330
            ->method('getForm')
331
            ->will($this->returnValue($form = 'form'));
332
333
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
334
            ->expects($this->once())
335
            ->method('getMasterRequest')
336
            ->will($this->returnValue($request = $this->createRequestMock()));
337
338
        $request->attributes
339
            ->expects($this->once())
340
            ->method('get')
341
            ->with($this->identicalTo('_lug_form'), $this->identicalTo($form))
342
            ->will($this->returnValue($explicitForm = 'explicit_form'));
343
344
        $this->assertSame($explicitForm, $this->parameterResolver->resolveForm($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 327 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...Resolver::resolveForm() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
345
    }
346
347
    public function testResolveGrid()
348
    {
349
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
350
            ->expects($this->exactly(2))
351
            ->method('getMasterRequest')
352
            ->will($this->returnValue($request = $this->createRequestMock()));
353
354
        $request->attributes
355
            ->expects($this->once())
356
            ->method('get')
357
            ->with($this->identicalTo('_lug_grid'), $this->identicalTo([]))
358
            ->will($this->returnValue($grid = ['foo' => 'bar']));
359
360
        $this->assertSame(
361
            array_merge(['resource' => $resource = $this->createResourceMock()], $grid),
362
            $this->parameterResolver->resolveGrid($resource)
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 361 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...Resolver::resolveGrid() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
363
        );
364
    }
365
366
    /**
367
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
368
     * @expectedExceptionMessage The request could not be found.
369
     */
370
    public function testResolveGridWithoutRequest()
371
    {
372
        $this->parameterResolver->resolveGrid($this->createResourceMock());
0 ignored issues
show
Bug introduced by
It seems like $this->createResourceMock() targeting Lug\Bundle\ResourceBundl...t::createResourceMock() can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...Resolver::resolveGrid() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
373
    }
374
375
    public function testResolveHateoasWithoutRequest()
376
    {
377
        $this->assertFalse($this->parameterResolver->resolveHateoas());
378
    }
379
380
    public function testResolveHateoasDefault()
381
    {
382
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
383
            ->expects($this->once())
384
            ->method('getMasterRequest')
385
            ->will($this->returnValue($request = $this->createRequestMock()));
386
387
        $request->attributes
388
            ->expects($this->once())
389
            ->method('get')
390
            ->with($this->identicalTo('_lug_hateoas'), $this->identicalTo($hateaos = false))
391
            ->will($this->returnValue($hateaos));
392
393
        $this->assertFalse($this->parameterResolver->resolveHateoas());
394
    }
395
396 View Code Duplication
    public function testResolveHateoasExplicit()
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...
397
    {
398
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
399
            ->expects($this->once())
400
            ->method('getMasterRequest')
401
            ->will($this->returnValue($request = $this->createRequestMock()));
402
403
        $request->attributes
404
            ->expects($this->once())
405
            ->method('get')
406
            ->with($this->identicalTo('_lug_hateoas'), $this->identicalTo(false))
407
            ->will($this->returnValue(true));
408
409
        $this->assertTrue($this->parameterResolver->resolveHateoas());
410
    }
411
412
    public function testResolveLocationRoute()
413
    {
414
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
415
            ->expects($this->exactly(2))
416
            ->method('getMasterRequest')
417
            ->will($this->returnValue($request = $this->createRequestMock()));
418
419
        $request->attributes
420
            ->expects($this->once())
421
            ->method('get')
422
            ->with($this->identicalTo('_lug_location_route'), $this->isNull())
423
            ->will($this->returnValue($route = 'route'));
424
425
        $this->assertSame($route, $this->parameterResolver->resolveLocationRoute());
426
    }
427
428
    /**
429
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
430
     * @expectedExceptionMessage The request could not be found.
431
     */
432
    public function testResolveLocationRouteWithoutRequest()
433
    {
434
        $this->parameterResolver->resolveLocationRoute();
435
    }
436
437
    /**
438
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
439
     * @expectedExceptionMessage The location route could not be found for the route "route".
440
     */
441 View Code Duplication
    public function testResolveLocationRouteMissing()
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...
442
    {
443
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
444
            ->expects($this->exactly(2))
445
            ->method('getMasterRequest')
446
            ->will($this->returnValue($request = $this->createRequestMock()));
447
448
        $request->attributes
449
            ->expects($this->at(0))
450
            ->method('get')
451
            ->with($this->identicalTo('_lug_location_route'), $this->isNull())
452
            ->will($this->returnValue(null));
453
454
        $request->attributes
455
            ->expects($this->at(1))
456
            ->method('get')
457
            ->with($this->identicalTo('_route'), $this->isNull())
458
            ->will($this->returnValue('route'));
459
460
        $this->parameterResolver->resolveLocationRoute();
461
    }
462
463
    public function testResolveLocationRouteParametersWithoutRequest()
464
    {
465
        $this->assertEmpty($this->parameterResolver->resolveLocationRouteParameters(new \stdClass()));
466
    }
467
468
    public function testResolveLocationRouteParametersDefault()
469
    {
470
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
471
            ->expects($this->once())
472
            ->method('getMasterRequest')
473
            ->will($this->returnValue($request = $this->createRequestMock()));
474
475
        $request->attributes
476
            ->expects($this->once())
477
            ->method('get')
478
            ->with($this->identicalTo('_lug_location_route_parameters'), $this->identicalTo($parameters = []))
479
            ->will($this->returnValue($parameters));
480
481
        $this->assertEmpty($this->parameterResolver->resolveLocationRouteParameters(new \stdClass()));
482
    }
483
484 View Code Duplication
    public function testResolveLocationRouteParametersExplicit()
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...
485
    {
486
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
487
            ->expects($this->once())
488
            ->method('getMasterRequest')
489
            ->will($this->returnValue($request = $this->createRequestMock()));
490
491
        $request->attributes
492
            ->expects($this->once())
493
            ->method('get')
494
            ->with($this->identicalTo('_lug_location_route_parameters'), $this->identicalTo([]))
495
            ->will($this->returnValue([$parameter = 'id']));
496
497
        $object = new \stdClass();
498
        $object->{$parameter} = $value = 1;
499
500
        $this->propertyAccessor
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Proper...opertyAccessorInterface.

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...
501
            ->expects($this->once())
502
            ->method('getValue')
503
            ->with($this->identicalTo($object), $this->identicalTo($parameter))
504
            ->will($this->returnValue($value));
505
506
        $this->assertSame([$parameter => $value], $this->parameterResolver->resolveLocationRouteParameters($object));
507
    }
508
509
    public function testResolveMaxPerPageWithoutRequest()
510
    {
511
        $this->assertSame(10, $this->parameterResolver->resolveMaxPerPage());
512
    }
513
514
    public function testResolveMaxPerPageDefault()
515
    {
516
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
517
            ->expects($this->once())
518
            ->method('getMasterRequest')
519
            ->will($this->returnValue($request = $this->createRequestMock()));
520
521
        $request->attributes
522
            ->expects($this->once())
523
            ->method('get')
524
            ->with($this->identicalTo('_lug_max_per_page'), $this->identicalTo($maxPerPage = 10))
525
            ->will($this->returnValue($maxPerPage));
526
527
        $this->assertSame($maxPerPage, $this->parameterResolver->resolveMaxPerPage());
528
    }
529
530
    public function testResolveMaxPerPageExplicit()
531
    {
532
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
533
            ->expects($this->once())
534
            ->method('getMasterRequest')
535
            ->will($this->returnValue($request = $this->createRequestMock()));
536
537
        $request->attributes
538
            ->expects($this->once())
539
            ->method('get')
540
            ->with($this->identicalTo('_lug_max_per_page'), $this->identicalTo(10))
541
            ->will($this->returnValue($maxPerPage = 5));
542
543
        $this->assertSame($maxPerPage, $this->parameterResolver->resolveMaxPerPage());
544
    }
545
546
    public function testResolveRedirectRoute()
547
    {
548
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
549
            ->expects($this->exactly(2))
550
            ->method('getMasterRequest')
551
            ->will($this->returnValue($request = $this->createRequestMock()));
552
553
        $request->attributes
554
            ->expects($this->once())
555
            ->method('get')
556
            ->with($this->identicalTo('_lug_redirect_route'), $this->isNull())
557
            ->will($this->returnValue($route = 'route'));
558
559
        $this->assertSame($route, $this->parameterResolver->resolveRedirectRoute());
560
    }
561
562
    /**
563
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
564
     * @expectedExceptionMessage The request could not be found.
565
     */
566
    public function testResolveRedirectRouteWithoutRequest()
567
    {
568
        $this->parameterResolver->resolveRedirectRoute();
569
    }
570
571
    /**
572
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
573
     * @expectedExceptionMessage The redirect route could not be found for the route "route".
574
     */
575 View Code Duplication
    public function testResolveRedirectRouteMissing()
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...
576
    {
577
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
578
            ->expects($this->exactly(2))
579
            ->method('getMasterRequest')
580
            ->will($this->returnValue($request = $this->createRequestMock()));
581
582
        $request->attributes
583
            ->expects($this->at(0))
584
            ->method('get')
585
            ->with($this->identicalTo('_lug_redirect_route'), $this->isNull())
586
            ->will($this->returnValue(null));
587
588
        $request->attributes
589
            ->expects($this->at(1))
590
            ->method('get')
591
            ->with($this->identicalTo('_route'), $this->isNull())
592
            ->will($this->returnValue('route'));
593
594
        $this->parameterResolver->resolveRedirectRoute();
595
    }
596
597
    public function testResolveRedirectRouteParametersWithoutRequest()
598
    {
599
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters(new \stdClass()));
600
    }
601
602
    public function testResolveRedirectRouteParametersDefault()
603
    {
604
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
605
            ->expects($this->once())
606
            ->method('getMasterRequest')
607
            ->will($this->returnValue($request = $this->createRequestMock()));
608
609
        $request->attributes
610
            ->expects($this->once())
611
            ->method('get')
612
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo($parameters = []))
613
            ->will($this->returnValue($parameters));
614
615
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters(new \stdClass()));
616
    }
617
618 View Code Duplication
    public function testResolveRedirectRouteParametersExplicit()
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...
619
    {
620
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
621
            ->expects($this->once())
622
            ->method('getMasterRequest')
623
            ->will($this->returnValue($request = $this->createRequestMock()));
624
625
        $request->attributes
626
            ->expects($this->once())
627
            ->method('get')
628
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
629
            ->will($this->returnValue([$parameter = 'id']));
630
631
        $object = new \stdClass();
632
        $object->{$parameter} = $value = 1;
633
634
        $this->propertyAccessor
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Proper...opertyAccessorInterface.

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...
635
            ->expects($this->once())
636
            ->method('getValue')
637
            ->with($this->identicalTo($object), $this->identicalTo($parameter))
638
            ->will($this->returnValue($value));
639
640
        $this->assertSame([$parameter => $value], $this->parameterResolver->resolveRedirectRouteParameters($object));
641
    }
642
643
    public function testResolveRedirectRouteParametersForwardParameters()
644
    {
645
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
646
            ->expects($this->exactly(2))
647
            ->method('getMasterRequest')
648
            ->will($this->returnValue($request = $this->createRequestMock()));
649
650
        $request->attributes
651
            ->expects($this->once())
652
            ->method('get')
653
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
654
            ->will($this->returnValue([$parameter = 'id']));
655
656
        $request->query = $this->createParameterBagMock();
657
        $request->query
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\ParameterBag.

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...
658
            ->expects($this->once())
659
            ->method('all')
660
            ->will($this->returnValue($query = ['foo' => 'bar']));
661
662
        $object = new \stdClass();
663
        $object->{$parameter} = $value = 1;
664
665
        $this->propertyAccessor
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\Proper...opertyAccessorInterface.

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...
666
            ->expects($this->once())
667
            ->method('getValue')
668
            ->with($this->identicalTo($object), $this->identicalTo($parameter))
669
            ->will($this->returnValue($value));
670
671
        $this->assertSame(
672
            array_merge($query, [$parameter => $value]),
673
            $this->parameterResolver->resolveRedirectRouteParameters($object, true)
674
        );
675
    }
676
677 View Code Duplication
    public function testResolveRedirectRouteParametersWithoutObject()
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...
678
    {
679
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
680
            ->expects($this->once())
681
            ->method('getMasterRequest')
682
            ->will($this->returnValue($request = $this->createRequestMock()));
683
684
        $request->attributes
685
            ->expects($this->once())
686
            ->method('get')
687
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
688
            ->will($this->returnValue([]));
689
690
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters());
691
    }
692
693
    /**
694
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
695
     * @expectedExceptionMessage The route parameters could not be found for the route "redirect_route_parameters".
696
     */
697 View Code Duplication
    public function testResolveRedirectRouteParametersWithObjectMissing()
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...
698
    {
699
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
700
            ->expects($this->once())
701
            ->method('getMasterRequest')
702
            ->will($this->returnValue($request = $this->createRequestMock()));
703
704
        $request->attributes
705
            ->expects($this->once())
706
            ->method('get')
707
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
708
            ->will($this->returnValue(['id']));
709
710
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters());
711
    }
712
713
    public function testResolveRedirectRouteParametersForwardWithoutRequest()
714
    {
715
        $this->assertFalse($this->parameterResolver->resolveRedirectRouteParametersForward());
716
    }
717
718
    public function testResolveRedirectRouteParametersForwardDefault()
719
    {
720
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
721
            ->expects($this->once())
722
            ->method('getMasterRequest')
723
            ->will($this->returnValue($request = $this->createRequestMock()));
724
725
        $request->attributes
726
            ->expects($this->once())
727
            ->method('get')
728
            ->with($this->identicalTo('_lug_redirect_route_parameters_forward'), $this->identicalTo($forward = false))
729
            ->will($this->returnValue($forward));
730
731
        $this->assertFalse($this->parameterResolver->resolveRedirectRouteParametersForward());
732
    }
733
734 View Code Duplication
    public function testResolveRedirectRouteParametersForwardExplicit()
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...
735
    {
736
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
737
            ->expects($this->once())
738
            ->method('getMasterRequest')
739
            ->will($this->returnValue($request = $this->createRequestMock()));
740
741
        $request->attributes
742
            ->expects($this->once())
743
            ->method('get')
744
            ->with($this->identicalTo('_lug_redirect_route_parameters_forward'), $this->identicalTo(false))
745
            ->will($this->returnValue(true));
746
747
        $this->assertTrue($this->parameterResolver->resolveRedirectRouteParametersForward());
748
    }
749
750
    public function testResolveRepositoryMethodWithoutRequest()
751
    {
752
        $this->assertSame('findForTest', $this->parameterResolver->resolveRepositoryMethod('test'));
753
    }
754
755
    public function testResolveRepositoryMethodDefault()
756
    {
757
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
758
            ->expects($this->once())
759
            ->method('getMasterRequest')
760
            ->will($this->returnValue($request = $this->createRequestMock()));
761
762
        $request->attributes
763
            ->expects($this->once())
764
            ->method('get')
765
            ->with($this->identicalTo('_lug_repository_method'), $this->identicalTo($repositoryMethod = 'findForTest'))
766
            ->will($this->returnValue($repositoryMethod));
767
768
        $this->assertSame($repositoryMethod, $this->parameterResolver->resolveRepositoryMethod('test'));
769
    }
770
771
    public function testResolveRepositoryMethodExplicit()
772
    {
773
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
774
            ->expects($this->once())
775
            ->method('getMasterRequest')
776
            ->will($this->returnValue($request = $this->createRequestMock()));
777
778
        $request->attributes
779
            ->expects($this->once())
780
            ->method('get')
781
            ->with($this->identicalTo('_lug_repository_method'), $this->identicalTo('findForTest'))
782
            ->will($this->returnValue($repositoryMethod = 'findForAction'));
783
784
        $this->assertSame($repositoryMethod, $this->parameterResolver->resolveRepositoryMethod('test'));
785
    }
786
787 View Code Duplication
    public function testResolveSerializerGroupsWithoutRequest()
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...
788
    {
789
        $resource = $this->createResourceMock();
790
        $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...
791
            ->expects($this->once())
792
            ->method('getName')
793
            ->will($this->returnValue($name = 'name'));
794
795
        $this->assertSame(
796
            [GroupsExclusionStrategy::DEFAULT_GROUP, 'lug.'.$name],
797
            $this->parameterResolver->resolveSerializerGroups($resource)
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 789 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...solveSerializerGroups() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
798
        );
799
    }
800
801 View Code Duplication
    public function testResolveSerializerGroupsDefault()
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...
802
    {
803
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
804
            ->expects($this->once())
805
            ->method('getMasterRequest')
806
            ->will($this->returnValue($request = $this->createRequestMock()));
807
808
        $resource = $this->createResourceMock();
809
        $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...
810
            ->expects($this->once())
811
            ->method('getName')
812
            ->will($this->returnValue($name = 'name'));
813
814
        $request->attributes
815
            ->expects($this->once())
816
            ->method('get')
817
            ->with(
818
                $this->identicalTo('_lug_serializer_groups'),
819
                $this->identicalTo($groups = [GroupsExclusionStrategy::DEFAULT_GROUP, 'lug.'.$name])
820
            )
821
            ->will($this->returnValue($groups));
822
823
        $this->assertSame($groups, $this->parameterResolver->resolveSerializerGroups($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 808 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...solveSerializerGroups() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
824
    }
825
826 View Code Duplication
    public function testResolveSerializerGroupsExplicit()
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...
827
    {
828
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
829
            ->expects($this->once())
830
            ->method('getMasterRequest')
831
            ->will($this->returnValue($request = $this->createRequestMock()));
832
833
        $resource = $this->createResourceMock();
834
        $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...
835
            ->expects($this->once())
836
            ->method('getName')
837
            ->will($this->returnValue($name = 'name'));
838
839
        $request->attributes
840
            ->expects($this->once())
841
            ->method('get')
842
            ->with(
843
                $this->identicalTo('_lug_serializer_groups'),
844
                $this->identicalTo([GroupsExclusionStrategy::DEFAULT_GROUP, 'lug.'.$name])
845
            )
846
            ->will($this->returnValue($groups = ['group']));
847
848
        $this->assertSame($groups, $this->parameterResolver->resolveSerializerGroups($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 833 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...solveSerializerGroups() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
849
    }
850
851
    public function testResolveSerializerNullWithoutRequest()
852
    {
853
        $this->assertTrue($this->parameterResolver->resolveSerializerNull());
854
    }
855
856 View Code Duplication
    public function testResolveSerializerNullDefault()
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...
857
    {
858
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
859
            ->expects($this->once())
860
            ->method('getMasterRequest')
861
            ->will($this->returnValue($request = $this->createRequestMock()));
862
863
        $request->attributes
864
            ->expects($this->once())
865
            ->method('get')
866
            ->with($this->identicalTo('_lug_serializer_null'), $this->identicalTo($null = true))
867
            ->will($this->returnValue($null));
868
869
        $this->assertTrue($this->parameterResolver->resolveSerializerNull());
870
    }
871
872
    public function testResolveSerializerNullExplicit()
873
    {
874
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
875
            ->expects($this->once())
876
            ->method('getMasterRequest')
877
            ->will($this->returnValue($request = $this->createRequestMock()));
878
879
        $request->attributes
880
            ->expects($this->once())
881
            ->method('get')
882
            ->with($this->identicalTo('_lug_serializer_null'), $this->identicalTo(true))
883
            ->will($this->returnValue(false));
884
885
        $this->assertFalse($this->parameterResolver->resolveSerializerNull());
886
    }
887
888
    public function testResolveSortingWithoutRequest()
889
    {
890
        $this->assertEmpty($this->parameterResolver->resolveSorting());
891
    }
892
893 View Code Duplication
    public function testResolveSortingDefault()
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...
894
    {
895
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
896
            ->expects($this->once())
897
            ->method('getMasterRequest')
898
            ->will($this->returnValue($request = $this->createRequestMock()));
899
900
        $request->attributes
901
            ->expects($this->once())
902
            ->method('get')
903
            ->with($this->identicalTo('_lug_sorting'), $this->identicalTo($sorting = []))
904
            ->will($this->returnValue($sorting));
905
906
        $this->assertEmpty($this->parameterResolver->resolveSorting());
907
    }
908
909 View Code Duplication
    public function testResolveSortingExplicit()
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...
910
    {
911
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
912
            ->expects($this->once())
913
            ->method('getMasterRequest')
914
            ->will($this->returnValue($request = $this->createRequestMock()));
915
916
        $request->attributes
917
            ->expects($this->once())
918
            ->method('get')
919
            ->with($this->identicalTo('_lug_sorting'), $this->identicalTo([]))
920
            ->will($this->returnValue($sorting = ['foo' => 'ASC']));
921
922
        $this->assertSame($sorting, $this->parameterResolver->resolveSorting());
923
    }
924
925
    public function testResolveTemplate()
926
    {
927
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
928
            ->expects($this->exactly(2))
929
            ->method('getMasterRequest')
930
            ->will($this->returnValue($request = $this->createRequestMock()));
931
932
        $request->attributes
933
            ->expects($this->once())
934
            ->method('get')
935
            ->with($this->identicalTo('_lug_template'), $this->isNull())
936
            ->will($this->returnValue($template = 'template'));
937
938
        $this->assertSame($template, $this->parameterResolver->resolveTemplate());
939
    }
940
941
    /**
942
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
943
     * @expectedExceptionMessage The request could not be found.
944
     */
945
    public function testResolveTemplateWithoutRequest()
946
    {
947
        $this->parameterResolver->resolveTemplate();
948
    }
949
950
    /**
951
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
952
     * @expectedExceptionMessage The template could not be found for the route "route".
953
     */
954 View Code Duplication
    public function testResolveTemplateMissing()
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...
955
    {
956
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
957
            ->expects($this->exactly(2))
958
            ->method('getMasterRequest')
959
            ->will($this->returnValue($request = $this->createRequestMock()));
960
961
        $request->attributes
962
            ->expects($this->at(0))
963
            ->method('get')
964
            ->with($this->identicalTo('_lug_template'), $this->isNull())
965
            ->will($this->returnValue(null));
966
967
        $request->attributes
968
            ->expects($this->at(1))
969
            ->method('get')
970
            ->with($this->identicalTo('_route'), $this->isNull())
971
            ->will($this->returnValue('route'));
972
973
        $this->parameterResolver->resolveTemplate();
974
    }
975
976
    public function testResolveThemesWithoutRequest()
977
    {
978
        $this->assertEmpty($this->parameterResolver->resolveThemes());
979
    }
980
981 View Code Duplication
    public function testResolveThemesDefault()
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...
982
    {
983
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
984
            ->expects($this->once())
985
            ->method('getMasterRequest')
986
            ->will($this->returnValue($request = $this->createRequestMock()));
987
988
        $request->attributes
989
            ->expects($this->once())
990
            ->method('get')
991
            ->with($this->identicalTo('_lug_themes'), $this->identicalTo($themes = []))
992
            ->will($this->returnValue($themes));
993
994
        $this->assertEmpty($this->parameterResolver->resolveThemes());
995
    }
996
997 View Code Duplication
    public function testResolveThemesExplicit()
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...
998
    {
999
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1000
            ->expects($this->once())
1001
            ->method('getMasterRequest')
1002
            ->will($this->returnValue($request = $this->createRequestMock()));
1003
1004
        $request->attributes
1005
            ->expects($this->once())
1006
            ->method('get')
1007
            ->with($this->identicalTo('_lug_themes'), $this->identicalTo([]))
1008
            ->will($this->returnValue($themes = ['theme']));
1009
1010
        $this->assertSame($themes, $this->parameterResolver->resolveThemes());
1011
    }
1012
1013
    public function testResolveTranslationDomainWithoutRequest()
1014
    {
1015
        $this->assertSame('forms', $this->parameterResolver->resolveTranslationDomain());
1016
    }
1017
1018 View Code Duplication
    public function testResolveTranslationDomainDefault()
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...
1019
    {
1020
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1021
            ->expects($this->exactly(2))
1022
            ->method('getMasterRequest')
1023
            ->will($this->returnValue($request = $this->createRequestMock()));
1024
1025
        $request->attributes
1026
            ->expects($this->at(0))
1027
            ->method('get')
1028
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1029
            ->will($this->returnValue(null));
1030
1031
        $request->attributes
1032
            ->expects($this->at(1))
1033
            ->method('get')
1034
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo($translationDomain = 'forms'))
1035
            ->will($this->returnValue($translationDomain));
1036
1037
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1038
    }
1039
1040 View Code Duplication
    public function testResolveTranslationDomainExplicit()
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...
1041
    {
1042
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1043
            ->expects($this->exactly(2))
1044
            ->method('getMasterRequest')
1045
            ->will($this->returnValue($request = $this->createRequestMock()));
1046
1047
        $request->attributes
1048
            ->expects($this->at(0))
1049
            ->method('get')
1050
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1051
            ->will($this->returnValue(null));
1052
1053
        $request->attributes
1054
            ->expects($this->at(1))
1055
            ->method('get')
1056
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo('forms'))
1057
            ->will($this->returnValue($translationDomain = 'translation_domain'));
1058
1059
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1060
    }
1061
1062 View Code Duplication
    public function testResolveTranslationDomainWithGrid()
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...
1063
    {
1064
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1065
            ->expects($this->exactly(2))
1066
            ->method('getMasterRequest')
1067
            ->will($this->returnValue($request = $this->createRequestMock()));
1068
1069
        $request->attributes
1070
            ->expects($this->at(0))
1071
            ->method('get')
1072
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1073
            ->will($this->returnValue(['grid']));
1074
1075
        $request->attributes
1076
            ->expects($this->at(1))
1077
            ->method('get')
1078
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo($translationDomain = 'grids'))
1079
            ->will($this->returnValue($translationDomain));
1080
1081
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1082
    }
1083
1084 View Code Duplication
    public function testResolveTranslationDomainExplicitWithGrid()
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...
1085
    {
1086
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1087
            ->expects($this->exactly(2))
1088
            ->method('getMasterRequest')
1089
            ->will($this->returnValue($request = $this->createRequestMock()));
1090
1091
        $request->attributes
1092
            ->expects($this->at(0))
1093
            ->method('get')
1094
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1095
            ->will($this->returnValue(['grid']));
1096
1097
        $request->attributes
1098
            ->expects($this->at(1))
1099
            ->method('get')
1100
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo('grids'))
1101
            ->will($this->returnValue($translationDomain = 'translation_domain'));
1102
1103
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1104
    }
1105
1106 View Code Duplication
    public function testResolveValidationGroupsWithoutRequest()
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...
1107
    {
1108
        $resource = $this->createResourceMock();
1109
        $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...
1110
            ->expects($this->once())
1111
            ->method('getName')
1112
            ->will($this->returnValue($name = 'name'));
1113
1114
        $this->assertSame(
1115
            [Constraint::DEFAULT_GROUP, 'lug.'.$name],
1116
            $this->parameterResolver->resolveValidationGroups($resource)
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 1108 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...solveValidationGroups() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
1117
        );
1118
    }
1119
1120 View Code Duplication
    public function testResolveValidationGroupsDefault()
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...
1121
    {
1122
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1123
            ->expects($this->once())
1124
            ->method('getMasterRequest')
1125
            ->will($this->returnValue($request = $this->createRequestMock()));
1126
1127
        $resource = $this->createResourceMock();
1128
        $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...
1129
            ->expects($this->once())
1130
            ->method('getName')
1131
            ->will($this->returnValue($name = 'name'));
1132
1133
        $request->attributes
1134
            ->expects($this->once())
1135
            ->method('get')
1136
            ->with(
1137
                $this->identicalTo('_lug_validation_groups'),
1138
                $this->identicalTo($groups = [Constraint::DEFAULT_GROUP, 'lug.'.$name])
1139
            )
1140
            ->will($this->returnValue($groups));
1141
1142
        $this->assertSame($groups, $this->parameterResolver->resolveValidationGroups($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 1127 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...solveValidationGroups() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
1143
    }
1144
1145 View Code Duplication
    public function testResolveValidationGroupsExplicit()
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...
1146
    {
1147
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1148
            ->expects($this->once())
1149
            ->method('getMasterRequest')
1150
            ->will($this->returnValue($request = $this->createRequestMock()));
1151
1152
        $resource = $this->createResourceMock();
1153
        $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...
1154
            ->expects($this->once())
1155
            ->method('getName')
1156
            ->will($this->returnValue($name = 'name'));
1157
1158
        $request->attributes
1159
            ->expects($this->once())
1160
            ->method('get')
1161
            ->with(
1162
                $this->identicalTo('_lug_validation_groups'),
1163
                $this->identicalTo([Constraint::DEFAULT_GROUP, 'lug.'.$name])
1164
            )
1165
            ->will($this->returnValue($groups = ['group']));
1166
1167
        $this->assertSame($groups, $this->parameterResolver->resolveValidationGroups($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 1152 can also be of type object<PHPUnit_Framework_MockObject_MockObject>; however, Lug\Bundle\ResourceBundl...solveValidationGroups() does only seem to accept object<Lug\Component\Res...odel\ResourceInterface>, 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...
1168
    }
1169
1170
    public function testResolveVoterWithoutRequest()
1171
    {
1172
        $this->assertFalse($this->parameterResolver->resolveVoter());
1173
    }
1174
1175
    public function testResolveVoterDefault()
1176
    {
1177
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1178
            ->expects($this->once())
1179
            ->method('getMasterRequest')
1180
            ->will($this->returnValue($request = $this->createRequestMock()));
1181
1182
        $request->attributes
1183
            ->expects($this->once())
1184
            ->method('get')
1185
            ->with($this->identicalTo('_lug_voter'), $this->identicalTo(false))
1186
            ->will($this->returnValue(false));
1187
1188
        $this->assertFalse($this->parameterResolver->resolveVoter());
1189
    }
1190
1191 View Code Duplication
    public function testResolveVoterExplicit()
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...
1192
    {
1193
        $this->requestStack
0 ignored issues
show
Bug introduced by
The method expects does only exist in PHPUnit_Framework_MockObject_MockObject, but not in Symfony\Component\HttpFoundation\RequestStack.

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...
1194
            ->expects($this->once())
1195
            ->method('getMasterRequest')
1196
            ->will($this->returnValue($request = $this->createRequestMock()));
1197
1198
        $request->attributes
1199
            ->expects($this->once())
1200
            ->method('get')
1201
            ->with($this->identicalTo('_lug_voter'), $this->identicalTo(false))
1202
            ->will($this->returnValue(true));
1203
1204
        $this->assertTrue($this->parameterResolver->resolveVoter());
1205
    }
1206
1207
    /**
1208
     * @return \PHPUnit_Framework_MockObject_MockObject|RequestStack
1209
     */
1210
    private function createRequestStackMock()
1211
    {
1212
        return $this->getMock(RequestStack::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...
1213
    }
1214
1215
    /**
1216
     * @return \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface
1217
     */
1218
    private function createPropertyAccessorMock()
1219
    {
1220
        return $this->getMock(PropertyAccessorInterface::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...
1221
    }
1222
1223
    /**
1224
     * @return \PHPUnit_Framework_MockObject_MockObject|Request
1225
     */
1226
    private function createRequestMock()
1227
    {
1228
        $request = $this->getMock(Request::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...
1229
        $request->attributes = $this->createParameterBagMock();
1230
1231
        return $request;
1232
    }
1233
1234
    /**
1235
     * @return \PHPUnit_Framework_MockObject_MockObject|ParameterBag
1236
     */
1237
    private function createParameterBagMock()
1238
    {
1239
        return $this->getMock(ParameterBag::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...
1240
    }
1241
1242
    /**
1243
     * @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
1244
     */
1245
    private function createResourceMock()
1246
    {
1247
        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...
1248
    }
1249
}
1250