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

testResolveSerializerNullWithoutRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Bundle\ResourceBundle\Tests\Routing;
13
14
use Lug\Bundle\ResourceBundle\Routing\ParameterResolver;
15
use Lug\Component\Resource\Model\ResourceInterface;
16
use Symfony\Component\HttpFoundation\ParameterBag;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\RequestStack;
19
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
20
use Symfony\Component\Validator\Constraint;
21
22
/**
23
 * @author GeLo <[email protected]>
24
 */
25
class ParameterResolverTest extends \PHPUnit_Framework_TestCase
26
{
27
    /**
28
     * @var ParameterResolver
29
     */
30
    private $parameterResolver;
31
32
    /**
33
     * @var \PHPUnit_Framework_MockObject_MockObject|RequestStack
34
     */
35
    private $requestStack;
36
37
    /**
38
     * @var \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface
39
     */
40
    private $propertyAccessor;
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    protected function setUp()
46
    {
47
        $this->requestStack = $this->createRequestStackMock();
48
        $this->propertyAccessor = $this->createPropertyAccessorMock();
49
50
        $this->parameterResolver = new ParameterResolver($this->requestStack, $this->propertyAccessor);
51
    }
52
53
    public function testResolveApiWithoutRequest()
54
    {
55
        $this->assertFalse($this->parameterResolver->resolveApi());
56
    }
57
58 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...
59
    {
60
        $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...
61
            ->expects($this->exactly(2))
62
            ->method('getMasterRequest')
63
            ->will($this->returnValue($request = $this->createRequestMock()));
64
65
        $request->attributes
66
            ->expects($this->once())
67
            ->method('get')
68
            ->with($this->identicalTo('_lug_api'), $this->identicalTo(false))
69
            ->will($this->returnValue(true));
70
71
        $this->assertTrue($this->parameterResolver->resolveApi());
72
    }
73
74 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...
75
    {
76
        $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...
77
            ->expects($this->exactly(2))
78
            ->method('getMasterRequest')
79
            ->will($this->returnValue($request = $this->createRequestMock()));
80
81
        $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...
82
            ->expects($this->once())
83
            ->method('getRequestFormat')
84
            ->will($this->returnValue('html'));
85
86
        $this->assertFalse($this->parameterResolver->resolveApi());
87
    }
88
89 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...
90
    {
91
        $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...
92
            ->expects($this->exactly(2))
93
            ->method('getMasterRequest')
94
            ->will($this->returnValue($request = $this->createRequestMock()));
95
96
        $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...
97
            ->expects($this->once())
98
            ->method('getRequestFormat')
99
            ->will($this->returnValue('json'));
100
101
        $this->assertTrue($this->parameterResolver->resolveApi());
102
    }
103
104
    public function testResolveCriteriaWithoutRequest()
105
    {
106
        $this->assertEmpty($this->parameterResolver->resolveCriteria());
107
    }
108
109 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...
110
    {
111
        $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...
112
            ->expects($this->exactly(2))
113
            ->method('getMasterRequest')
114
            ->will($this->returnValue($request = $this->createRequestMock()));
115
116
        $request->attributes
117
            ->expects($this->once())
118
            ->method('get')
119
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo([$identifier = 'id']))
120
            ->will($this->returnValue([$identifier]));
121
122
        $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...
123
            ->expects($this->once())
124
            ->method('get')
125
            ->with($this->identicalTo($identifier), $this->isNull())
126
            ->will($this->returnValue($value = 'value'));
127
128
        $this->assertSame([$identifier => $value], $this->parameterResolver->resolveCriteria());
129
    }
130
131 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...
132
    {
133
        $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...
134
            ->expects($this->exactly(2))
135
            ->method('getMasterRequest')
136
            ->will($this->returnValue($request = $this->createRequestMock()));
137
138
        $request->attributes
139
            ->expects($this->once())
140
            ->method('get')
141
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo(['id']))
142
            ->will($this->returnValue([$identifier = 'code']));
143
144
        $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...
145
            ->expects($this->once())
146
            ->method('get')
147
            ->with($this->identicalTo($identifier), $this->isNull())
148
            ->will($this->returnValue($value = 'value'));
149
150
        $this->assertSame([$identifier => $value], $this->parameterResolver->resolveCriteria());
151
    }
152
153
    /**
154
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
155
     * @expectedExceptionMessage The request could not be found.
156
     */
157
    public function testResolveCriteriaMandatoryWithoutRequest()
158
    {
159
        $this->parameterResolver->resolveCriteria(true);
160
    }
161
162
    /**
163
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
164
     * @expectedExceptionMessage The criteria could not be found for the route "route".
165
     */
166 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...
167
    {
168
        $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...
169
            ->expects($this->exactly(2))
170
            ->method('getMasterRequest')
171
            ->will($this->returnValue($request = $this->createRequestMock()));
172
173
        $request->attributes
174
            ->expects($this->at(0))
175
            ->method('get')
176
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo(['id']))
177
            ->will($this->returnValue([]));
178
179
        $request->attributes
180
            ->expects($this->at(1))
181
            ->method('get')
182
            ->with($this->identicalTo('_route'), $this->isNull())
183
            ->will($this->returnValue('route'));
184
185
        $this->parameterResolver->resolveCriteria(true);
186
    }
187
188
    /**
189
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
190
     * @expectedExceptionMessage The criteria "id" could not be found for the route "route".
191
     */
192
    public function testResolveCriteriaMandatoryWithoutRequestCriteria()
193
    {
194
        $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...
195
            ->expects($this->exactly(2))
196
            ->method('getMasterRequest')
197
            ->will($this->returnValue($request = $this->createRequestMock()));
198
199
        $request->attributes
200
            ->expects($this->at(0))
201
            ->method('get')
202
            ->with($this->identicalTo('_lug_criteria'), $this->identicalTo([$identifier = 'id']))
203
            ->will($this->returnValue([$identifier]));
204
205
        $request->attributes
206
            ->expects($this->at(1))
207
            ->method('get')
208
            ->with($this->identicalTo('_route'), $this->isNull())
209
            ->will($this->returnValue('route'));
210
211
        $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...
212
            ->expects($this->once())
213
            ->method('get')
214
            ->with($this->identicalTo($identifier), $this->isNull())
215
            ->will($this->returnValue(null));
216
217
        $this->parameterResolver->resolveCriteria(true);
218
    }
219
220
    public function testResolveCurrentPageWithoutRequest()
221
    {
222
        $this->assertSame(1, $this->parameterResolver->resolveCurrentPage());
223
    }
224
225
    public function testResolveCurrentPageDefault()
226
    {
227
        $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...
228
            ->expects($this->exactly(2))
229
            ->method('getMasterRequest')
230
            ->will($this->returnValue($request = $this->createRequestMock()));
231
232
        $request->attributes
233
            ->expects($this->once())
234
            ->method('get')
235
            ->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo($pageParameter = 'page'))
236
            ->will($this->returnValue($pageParameter));
237
238
        $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...
239
            ->expects($this->once())
240
            ->method('get')
241
            ->with($this->identicalTo($pageParameter), $this->identicalTo($page = 1))
242
            ->will($this->returnValue($page));
243
244
        $this->assertSame($page, $this->parameterResolver->resolveCurrentPage());
245
    }
246
247 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...
248
    {
249
        $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...
250
            ->expects($this->exactly(2))
251
            ->method('getMasterRequest')
252
            ->will($this->returnValue($request = $this->createRequestMock()));
253
254
        $request->attributes
255
            ->expects($this->once())
256
            ->method('get')
257
            ->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo('page'))
258
            ->will($this->returnValue($pageParameter = 'p'));
259
260
        $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...
261
            ->expects($this->once())
262
            ->method('get')
263
            ->with($this->identicalTo($pageParameter), $this->identicalTo($page = 1))
264
            ->will($this->returnValue($page));
265
266
        $this->assertSame($page, $this->parameterResolver->resolveCurrentPage());
267
    }
268
269 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...
270
    {
271
        $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...
272
            ->expects($this->exactly(2))
273
            ->method('getMasterRequest')
274
            ->will($this->returnValue($request = $this->createRequestMock()));
275
276
        $request->attributes
277
            ->expects($this->once())
278
            ->method('get')
279
            ->with($this->identicalTo('_lug_page_parameter'), $this->identicalTo($pageParameter = 'page'))
280
            ->will($this->returnValue($pageParameter));
281
282
        $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...
283
            ->expects($this->once())
284
            ->method('get')
285
            ->with($this->identicalTo($pageParameter), $this->identicalTo(1))
286
            ->will($this->returnValue($page = 2));
287
288
        $this->assertSame($page, $this->parameterResolver->resolveCurrentPage());
289
    }
290
291 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...
292
    {
293
        $resource = $this->createResourceMock();
294
        $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...
295
            ->expects($this->once())
296
            ->method('getForm')
297
            ->will($this->returnValue($form = 'form'));
298
299
        $this->assertSame($form, $this->parameterResolver->resolveForm($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 293 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...
300
    }
301
302
    public function testResolveFormDefault()
303
    {
304
        $resource = $this->createResourceMock();
305
        $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...
306
            ->expects($this->once())
307
            ->method('getForm')
308
            ->will($this->returnValue($form = 'form'));
309
310
        $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...
311
            ->expects($this->once())
312
            ->method('getMasterRequest')
313
            ->will($this->returnValue($request = $this->createRequestMock()));
314
315
        $request->attributes
316
            ->expects($this->once())
317
            ->method('get')
318
            ->with($this->identicalTo('_lug_form'), $this->identicalTo($form))
319
            ->will($this->returnValue($form));
320
321
        $this->assertSame($form, $this->parameterResolver->resolveForm($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 304 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...
322
    }
323
324 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...
325
    {
326
        $resource = $this->createResourceMock();
327
        $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...
328
            ->expects($this->once())
329
            ->method('getForm')
330
            ->will($this->returnValue($form = 'form'));
331
332
        $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...
333
            ->expects($this->once())
334
            ->method('getMasterRequest')
335
            ->will($this->returnValue($request = $this->createRequestMock()));
336
337
        $request->attributes
338
            ->expects($this->once())
339
            ->method('get')
340
            ->with($this->identicalTo('_lug_form'), $this->identicalTo($form))
341
            ->will($this->returnValue($explicitForm = 'explicit_form'));
342
343
        $this->assertSame($explicitForm, $this->parameterResolver->resolveForm($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 326 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...
344
    }
345
346
    public function testResolveGrid()
347
    {
348
        $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...
349
            ->expects($this->exactly(2))
350
            ->method('getMasterRequest')
351
            ->will($this->returnValue($request = $this->createRequestMock()));
352
353
        $request->attributes
354
            ->expects($this->once())
355
            ->method('get')
356
            ->with($this->identicalTo('_lug_grid'), $this->identicalTo([]))
357
            ->will($this->returnValue($grid = ['foo' => 'bar']));
358
359
        $this->assertSame(
360
            array_merge(['resource' => $resource = $this->createResourceMock()], $grid),
361
            $this->parameterResolver->resolveGrid($resource)
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 360 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...
362
        );
363
    }
364
365
    /**
366
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
367
     * @expectedExceptionMessage The request could not be found.
368
     */
369
    public function testResolveGridWithoutRequest()
370
    {
371
        $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...
372
    }
373
374
    public function testResolveHateoasWithoutRequest()
375
    {
376
        $this->assertFalse($this->parameterResolver->resolveHateoas());
377
    }
378
379
    public function testResolveHateoasDefault()
380
    {
381
        $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...
382
            ->expects($this->once())
383
            ->method('getMasterRequest')
384
            ->will($this->returnValue($request = $this->createRequestMock()));
385
386
        $request->attributes
387
            ->expects($this->once())
388
            ->method('get')
389
            ->with($this->identicalTo('_lug_hateoas'), $this->identicalTo($hateaos = false))
390
            ->will($this->returnValue($hateaos));
391
392
        $this->assertFalse($this->parameterResolver->resolveHateoas());
393
    }
394
395 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...
396
    {
397
        $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...
398
            ->expects($this->once())
399
            ->method('getMasterRequest')
400
            ->will($this->returnValue($request = $this->createRequestMock()));
401
402
        $request->attributes
403
            ->expects($this->once())
404
            ->method('get')
405
            ->with($this->identicalTo('_lug_hateoas'), $this->identicalTo(false))
406
            ->will($this->returnValue(true));
407
408
        $this->assertTrue($this->parameterResolver->resolveHateoas());
409
    }
410
411
    public function testResolveLocationRoute()
412
    {
413
        $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...
414
            ->expects($this->exactly(2))
415
            ->method('getMasterRequest')
416
            ->will($this->returnValue($request = $this->createRequestMock()));
417
418
        $request->attributes
419
            ->expects($this->once())
420
            ->method('get')
421
            ->with($this->identicalTo('_lug_location_route'), $this->isNull())
422
            ->will($this->returnValue($route = 'route'));
423
424
        $this->assertSame($route, $this->parameterResolver->resolveLocationRoute());
425
    }
426
427
    /**
428
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
429
     * @expectedExceptionMessage The request could not be found.
430
     */
431
    public function testResolveLocationRouteWithoutRequest()
432
    {
433
        $this->parameterResolver->resolveLocationRoute();
434
    }
435
436
    /**
437
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
438
     * @expectedExceptionMessage The location route could not be found for the route "route".
439
     */
440 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...
441
    {
442
        $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...
443
            ->expects($this->exactly(2))
444
            ->method('getMasterRequest')
445
            ->will($this->returnValue($request = $this->createRequestMock()));
446
447
        $request->attributes
448
            ->expects($this->at(0))
449
            ->method('get')
450
            ->with($this->identicalTo('_lug_location_route'), $this->isNull())
451
            ->will($this->returnValue(null));
452
453
        $request->attributes
454
            ->expects($this->at(1))
455
            ->method('get')
456
            ->with($this->identicalTo('_route'), $this->isNull())
457
            ->will($this->returnValue('route'));
458
459
        $this->parameterResolver->resolveLocationRoute();
460
    }
461
462
    public function testResolveLocationRouteParametersWithoutRequest()
463
    {
464
        $this->assertEmpty($this->parameterResolver->resolveLocationRouteParameters(new \stdClass()));
465
    }
466
467
    public function testResolveLocationRouteParametersDefault()
468
    {
469
        $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...
470
            ->expects($this->once())
471
            ->method('getMasterRequest')
472
            ->will($this->returnValue($request = $this->createRequestMock()));
473
474
        $request->attributes
475
            ->expects($this->once())
476
            ->method('get')
477
            ->with($this->identicalTo('_lug_location_route_parameters'), $this->identicalTo($parameters = []))
478
            ->will($this->returnValue($parameters));
479
480
        $this->assertEmpty($this->parameterResolver->resolveLocationRouteParameters(new \stdClass()));
481
    }
482
483 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...
484
    {
485
        $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...
486
            ->expects($this->once())
487
            ->method('getMasterRequest')
488
            ->will($this->returnValue($request = $this->createRequestMock()));
489
490
        $request->attributes
491
            ->expects($this->once())
492
            ->method('get')
493
            ->with($this->identicalTo('_lug_location_route_parameters'), $this->identicalTo([]))
494
            ->will($this->returnValue([$parameter = 'id']));
495
496
        $object = new \stdClass();
497
        $object->{$parameter} = $value = 1;
498
499
        $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...
500
            ->expects($this->once())
501
            ->method('getValue')
502
            ->with($this->identicalTo($object), $this->identicalTo($parameter))
503
            ->will($this->returnValue($value));
504
505
        $this->assertSame([$parameter => $value], $this->parameterResolver->resolveLocationRouteParameters($object));
506
    }
507
508
    public function testResolveMaxPerPageWithoutRequest()
509
    {
510
        $this->assertSame(10, $this->parameterResolver->resolveMaxPerPage());
511
    }
512
513
    public function testResolveMaxPerPageDefault()
514
    {
515
        $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...
516
            ->expects($this->once())
517
            ->method('getMasterRequest')
518
            ->will($this->returnValue($request = $this->createRequestMock()));
519
520
        $request->attributes
521
            ->expects($this->once())
522
            ->method('get')
523
            ->with($this->identicalTo('_lug_max_per_page'), $this->identicalTo($maxPerPage = 10))
524
            ->will($this->returnValue($maxPerPage));
525
526
        $this->assertSame($maxPerPage, $this->parameterResolver->resolveMaxPerPage());
527
    }
528
529
    public function testResolveMaxPerPageExplicit()
530
    {
531
        $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...
532
            ->expects($this->once())
533
            ->method('getMasterRequest')
534
            ->will($this->returnValue($request = $this->createRequestMock()));
535
536
        $request->attributes
537
            ->expects($this->once())
538
            ->method('get')
539
            ->with($this->identicalTo('_lug_max_per_page'), $this->identicalTo(10))
540
            ->will($this->returnValue($maxPerPage = 5));
541
542
        $this->assertSame($maxPerPage, $this->parameterResolver->resolveMaxPerPage());
543
    }
544
545
    public function testResolveRedirectRoute()
546
    {
547
        $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...
548
            ->expects($this->exactly(2))
549
            ->method('getMasterRequest')
550
            ->will($this->returnValue($request = $this->createRequestMock()));
551
552
        $request->attributes
553
            ->expects($this->once())
554
            ->method('get')
555
            ->with($this->identicalTo('_lug_redirect_route'), $this->isNull())
556
            ->will($this->returnValue($route = 'route'));
557
558
        $this->assertSame($route, $this->parameterResolver->resolveRedirectRoute());
559
    }
560
561
    /**
562
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
563
     * @expectedExceptionMessage The request could not be found.
564
     */
565
    public function testResolveRedirectRouteWithoutRequest()
566
    {
567
        $this->parameterResolver->resolveRedirectRoute();
568
    }
569
570
    /**
571
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
572
     * @expectedExceptionMessage The redirect route could not be found for the route "route".
573
     */
574 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...
575
    {
576
        $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...
577
            ->expects($this->exactly(2))
578
            ->method('getMasterRequest')
579
            ->will($this->returnValue($request = $this->createRequestMock()));
580
581
        $request->attributes
582
            ->expects($this->at(0))
583
            ->method('get')
584
            ->with($this->identicalTo('_lug_redirect_route'), $this->isNull())
585
            ->will($this->returnValue(null));
586
587
        $request->attributes
588
            ->expects($this->at(1))
589
            ->method('get')
590
            ->with($this->identicalTo('_route'), $this->isNull())
591
            ->will($this->returnValue('route'));
592
593
        $this->parameterResolver->resolveRedirectRoute();
594
    }
595
596
    public function testResolveRedirectRouteParametersWithoutRequest()
597
    {
598
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters(new \stdClass()));
599
    }
600
601
    public function testResolveRedirectRouteParametersDefault()
602
    {
603
        $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...
604
            ->expects($this->once())
605
            ->method('getMasterRequest')
606
            ->will($this->returnValue($request = $this->createRequestMock()));
607
608
        $request->attributes
609
            ->expects($this->once())
610
            ->method('get')
611
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo($parameters = []))
612
            ->will($this->returnValue($parameters));
613
614
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters(new \stdClass()));
615
    }
616
617 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...
618
    {
619
        $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...
620
            ->expects($this->once())
621
            ->method('getMasterRequest')
622
            ->will($this->returnValue($request = $this->createRequestMock()));
623
624
        $request->attributes
625
            ->expects($this->once())
626
            ->method('get')
627
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
628
            ->will($this->returnValue([$parameter = 'id']));
629
630
        $object = new \stdClass();
631
        $object->{$parameter} = $value = 1;
632
633
        $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...
634
            ->expects($this->once())
635
            ->method('getValue')
636
            ->with($this->identicalTo($object), $this->identicalTo($parameter))
637
            ->will($this->returnValue($value));
638
639
        $this->assertSame([$parameter => $value], $this->parameterResolver->resolveRedirectRouteParameters($object));
640
    }
641
642
    public function testResolveRedirectRouteParametersForwardParameters()
643
    {
644
        $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...
645
            ->expects($this->exactly(2))
646
            ->method('getMasterRequest')
647
            ->will($this->returnValue($request = $this->createRequestMock()));
648
649
        $request->attributes
650
            ->expects($this->once())
651
            ->method('get')
652
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
653
            ->will($this->returnValue([$parameter = 'id']));
654
655
        $request->query = $this->createParameterBagMock();
656
        $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...
657
            ->expects($this->once())
658
            ->method('all')
659
            ->will($this->returnValue($query = ['foo' => 'bar']));
660
661
        $object = new \stdClass();
662
        $object->{$parameter} = $value = 1;
663
664
        $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...
665
            ->expects($this->once())
666
            ->method('getValue')
667
            ->with($this->identicalTo($object), $this->identicalTo($parameter))
668
            ->will($this->returnValue($value));
669
670
        $this->assertSame(
671
            array_merge($query, [$parameter => $value]),
672
            $this->parameterResolver->resolveRedirectRouteParameters($object, true)
673
        );
674
    }
675
676 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...
677
    {
678
        $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...
679
            ->expects($this->once())
680
            ->method('getMasterRequest')
681
            ->will($this->returnValue($request = $this->createRequestMock()));
682
683
        $request->attributes
684
            ->expects($this->once())
685
            ->method('get')
686
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
687
            ->will($this->returnValue([]));
688
689
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters());
690
    }
691
692
    /**
693
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
694
     * @expectedExceptionMessage The route parameters could not be found for the route "redirect_route_parameters".
695
     */
696 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...
697
    {
698
        $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...
699
            ->expects($this->once())
700
            ->method('getMasterRequest')
701
            ->will($this->returnValue($request = $this->createRequestMock()));
702
703
        $request->attributes
704
            ->expects($this->once())
705
            ->method('get')
706
            ->with($this->identicalTo('_lug_redirect_route_parameters'), $this->identicalTo([]))
707
            ->will($this->returnValue(['id']));
708
709
        $this->assertEmpty($this->parameterResolver->resolveRedirectRouteParameters());
710
    }
711
712
    public function testResolveRedirectRouteParametersForwardWithoutRequest()
713
    {
714
        $this->assertFalse($this->parameterResolver->resolveRedirectRouteParametersForward());
715
    }
716
717
    public function testResolveRedirectRouteParametersForwardDefault()
718
    {
719
        $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...
720
            ->expects($this->once())
721
            ->method('getMasterRequest')
722
            ->will($this->returnValue($request = $this->createRequestMock()));
723
724
        $request->attributes
725
            ->expects($this->once())
726
            ->method('get')
727
            ->with($this->identicalTo('_lug_redirect_route_parameters_forward'), $this->identicalTo($forward = false))
728
            ->will($this->returnValue($forward));
729
730
        $this->assertFalse($this->parameterResolver->resolveRedirectRouteParametersForward());
731
    }
732
733 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...
734
    {
735
        $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...
736
            ->expects($this->once())
737
            ->method('getMasterRequest')
738
            ->will($this->returnValue($request = $this->createRequestMock()));
739
740
        $request->attributes
741
            ->expects($this->once())
742
            ->method('get')
743
            ->with($this->identicalTo('_lug_redirect_route_parameters_forward'), $this->identicalTo(false))
744
            ->will($this->returnValue(true));
745
746
        $this->assertTrue($this->parameterResolver->resolveRedirectRouteParametersForward());
747
    }
748
749
    public function testResolveRepositoryMethodWithoutRequest()
750
    {
751
        $this->assertSame('findForTest', $this->parameterResolver->resolveRepositoryMethod('test'));
752
    }
753
754
    public function testResolveRepositoryMethodDefault()
755
    {
756
        $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...
757
            ->expects($this->once())
758
            ->method('getMasterRequest')
759
            ->will($this->returnValue($request = $this->createRequestMock()));
760
761
        $request->attributes
762
            ->expects($this->once())
763
            ->method('get')
764
            ->with($this->identicalTo('_lug_repository_method'), $this->identicalTo($repositoryMethod = 'findForTest'))
765
            ->will($this->returnValue($repositoryMethod));
766
767
        $this->assertSame($repositoryMethod, $this->parameterResolver->resolveRepositoryMethod('test'));
768
    }
769
770
    public function testResolveRepositoryMethodExplicit()
771
    {
772
        $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...
773
            ->expects($this->once())
774
            ->method('getMasterRequest')
775
            ->will($this->returnValue($request = $this->createRequestMock()));
776
777
        $request->attributes
778
            ->expects($this->once())
779
            ->method('get')
780
            ->with($this->identicalTo('_lug_repository_method'), $this->identicalTo('findForTest'))
781
            ->will($this->returnValue($repositoryMethod = 'findForAction'));
782
783
        $this->assertSame($repositoryMethod, $this->parameterResolver->resolveRepositoryMethod('test'));
784
    }
785
786
    public function testResolveSerializerGroupsWithoutRequest()
787
    {
788
        $this->assertEmpty($this->parameterResolver->resolveSerializerGroups());
789
    }
790
791 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...
792
    {
793
        $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...
794
            ->expects($this->once())
795
            ->method('getMasterRequest')
796
            ->will($this->returnValue($request = $this->createRequestMock()));
797
798
        $request->attributes
799
            ->expects($this->once())
800
            ->method('get')
801
            ->with($this->identicalTo('_lug_serializer_groups'), $this->identicalTo($groups = []))
802
            ->will($this->returnValue($groups));
803
804
        $this->assertEmpty($this->parameterResolver->resolveSerializerGroups());
805
    }
806
807 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...
808
    {
809
        $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...
810
            ->expects($this->once())
811
            ->method('getMasterRequest')
812
            ->will($this->returnValue($request = $this->createRequestMock()));
813
814
        $request->attributes
815
            ->expects($this->once())
816
            ->method('get')
817
            ->with($this->identicalTo('_lug_serializer_groups'), $this->identicalTo([]))
818
            ->will($this->returnValue($groups = ['group']));
819
820
        $this->assertSame($groups, $this->parameterResolver->resolveSerializerGroups());
821
    }
822
823
    public function testResolveSerializerNullWithoutRequest()
824
    {
825
        $this->assertTrue($this->parameterResolver->resolveSerializerNull());
826
    }
827
828 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...
829
    {
830
        $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...
831
            ->expects($this->once())
832
            ->method('getMasterRequest')
833
            ->will($this->returnValue($request = $this->createRequestMock()));
834
835
        $request->attributes
836
            ->expects($this->once())
837
            ->method('get')
838
            ->with($this->identicalTo('_lug_serializer_null'), $this->identicalTo($null = true))
839
            ->will($this->returnValue($null));
840
841
        $this->assertTrue($this->parameterResolver->resolveSerializerNull());
842
    }
843
844
    public function testResolveSerializerNullExplicit()
845
    {
846
        $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...
847
            ->expects($this->once())
848
            ->method('getMasterRequest')
849
            ->will($this->returnValue($request = $this->createRequestMock()));
850
851
        $request->attributes
852
            ->expects($this->once())
853
            ->method('get')
854
            ->with($this->identicalTo('_lug_serializer_null'), $this->identicalTo(true))
855
            ->will($this->returnValue(false));
856
857
        $this->assertFalse($this->parameterResolver->resolveSerializerNull());
858
    }
859
860
    public function testResolveSortingWithoutRequest()
861
    {
862
        $this->assertEmpty($this->parameterResolver->resolveSorting());
863
    }
864
865 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...
866
    {
867
        $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...
868
            ->expects($this->once())
869
            ->method('getMasterRequest')
870
            ->will($this->returnValue($request = $this->createRequestMock()));
871
872
        $request->attributes
873
            ->expects($this->once())
874
            ->method('get')
875
            ->with($this->identicalTo('_lug_sorting'), $this->identicalTo($sorting = []))
876
            ->will($this->returnValue($sorting));
877
878
        $this->assertEmpty($this->parameterResolver->resolveSorting());
879
    }
880
881 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...
882
    {
883
        $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...
884
            ->expects($this->once())
885
            ->method('getMasterRequest')
886
            ->will($this->returnValue($request = $this->createRequestMock()));
887
888
        $request->attributes
889
            ->expects($this->once())
890
            ->method('get')
891
            ->with($this->identicalTo('_lug_sorting'), $this->identicalTo([]))
892
            ->will($this->returnValue($sorting = ['foo' => 'ASC']));
893
894
        $this->assertSame($sorting, $this->parameterResolver->resolveSorting());
895
    }
896
897
    public function testResolveTemplate()
898
    {
899
        $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...
900
            ->expects($this->exactly(2))
901
            ->method('getMasterRequest')
902
            ->will($this->returnValue($request = $this->createRequestMock()));
903
904
        $request->attributes
905
            ->expects($this->once())
906
            ->method('get')
907
            ->with($this->identicalTo('_lug_template'), $this->isNull())
908
            ->will($this->returnValue($template = 'template'));
909
910
        $this->assertSame($template, $this->parameterResolver->resolveTemplate());
911
    }
912
913
    /**
914
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RequestNotFoundException
915
     * @expectedExceptionMessage The request could not be found.
916
     */
917
    public function testResolveTemplateWithoutRequest()
918
    {
919
        $this->parameterResolver->resolveTemplate();
920
    }
921
922
    /**
923
     * @expectedException \Lug\Bundle\ResourceBundle\Exception\RuntimeException
924
     * @expectedExceptionMessage The template could not be found for the route "route".
925
     */
926 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...
927
    {
928
        $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...
929
            ->expects($this->exactly(2))
930
            ->method('getMasterRequest')
931
            ->will($this->returnValue($request = $this->createRequestMock()));
932
933
        $request->attributes
934
            ->expects($this->at(0))
935
            ->method('get')
936
            ->with($this->identicalTo('_lug_template'), $this->isNull())
937
            ->will($this->returnValue(null));
938
939
        $request->attributes
940
            ->expects($this->at(1))
941
            ->method('get')
942
            ->with($this->identicalTo('_route'), $this->isNull())
943
            ->will($this->returnValue('route'));
944
945
        $this->parameterResolver->resolveTemplate();
946
    }
947
948
    public function testResolveThemesWithoutRequest()
949
    {
950
        $this->assertEmpty($this->parameterResolver->resolveThemes());
951
    }
952
953 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...
954
    {
955
        $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...
956
            ->expects($this->once())
957
            ->method('getMasterRequest')
958
            ->will($this->returnValue($request = $this->createRequestMock()));
959
960
        $request->attributes
961
            ->expects($this->once())
962
            ->method('get')
963
            ->with($this->identicalTo('_lug_themes'), $this->identicalTo($themes = []))
964
            ->will($this->returnValue($themes));
965
966
        $this->assertEmpty($this->parameterResolver->resolveThemes());
967
    }
968
969 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...
970
    {
971
        $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...
972
            ->expects($this->once())
973
            ->method('getMasterRequest')
974
            ->will($this->returnValue($request = $this->createRequestMock()));
975
976
        $request->attributes
977
            ->expects($this->once())
978
            ->method('get')
979
            ->with($this->identicalTo('_lug_themes'), $this->identicalTo([]))
980
            ->will($this->returnValue($themes = ['theme']));
981
982
        $this->assertSame($themes, $this->parameterResolver->resolveThemes());
983
    }
984
985
    public function testResolveTranslationDomainWithoutRequest()
986
    {
987
        $this->assertSame('forms', $this->parameterResolver->resolveTranslationDomain());
988
    }
989
990 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...
991
    {
992
        $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...
993
            ->expects($this->exactly(2))
994
            ->method('getMasterRequest')
995
            ->will($this->returnValue($request = $this->createRequestMock()));
996
997
        $request->attributes
998
            ->expects($this->at(0))
999
            ->method('get')
1000
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1001
            ->will($this->returnValue(null));
1002
1003
        $request->attributes
1004
            ->expects($this->at(1))
1005
            ->method('get')
1006
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo($translationDomain = 'forms'))
1007
            ->will($this->returnValue($translationDomain));
1008
1009
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1010
    }
1011
1012 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...
1013
    {
1014
        $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...
1015
            ->expects($this->exactly(2))
1016
            ->method('getMasterRequest')
1017
            ->will($this->returnValue($request = $this->createRequestMock()));
1018
1019
        $request->attributes
1020
            ->expects($this->at(0))
1021
            ->method('get')
1022
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1023
            ->will($this->returnValue(null));
1024
1025
        $request->attributes
1026
            ->expects($this->at(1))
1027
            ->method('get')
1028
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo('forms'))
1029
            ->will($this->returnValue($translationDomain = 'translation_domain'));
1030
1031
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1032
    }
1033
1034 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...
1035
    {
1036
        $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...
1037
            ->expects($this->exactly(2))
1038
            ->method('getMasterRequest')
1039
            ->will($this->returnValue($request = $this->createRequestMock()));
1040
1041
        $request->attributes
1042
            ->expects($this->at(0))
1043
            ->method('get')
1044
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1045
            ->will($this->returnValue(['grid']));
1046
1047
        $request->attributes
1048
            ->expects($this->at(1))
1049
            ->method('get')
1050
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo($translationDomain = 'grids'))
1051
            ->will($this->returnValue($translationDomain));
1052
1053
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1054
    }
1055
1056 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...
1057
    {
1058
        $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...
1059
            ->expects($this->exactly(2))
1060
            ->method('getMasterRequest')
1061
            ->will($this->returnValue($request = $this->createRequestMock()));
1062
1063
        $request->attributes
1064
            ->expects($this->at(0))
1065
            ->method('get')
1066
            ->with($this->identicalTo('_lug_grid'), $this->isNull())
1067
            ->will($this->returnValue(['grid']));
1068
1069
        $request->attributes
1070
            ->expects($this->at(1))
1071
            ->method('get')
1072
            ->with($this->identicalTo('_lug_translation_domain'), $this->identicalTo('grids'))
1073
            ->will($this->returnValue($translationDomain = 'translation_domain'));
1074
1075
        $this->assertSame($translationDomain, $this->parameterResolver->resolveTranslationDomain());
1076
    }
1077
1078 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...
1079
    {
1080
        $resource = $this->createResourceMock();
1081
        $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...
1082
            ->expects($this->once())
1083
            ->method('getName')
1084
            ->will($this->returnValue($name = 'name'));
1085
1086
        $this->assertSame(
1087
            [Constraint::DEFAULT_GROUP, 'lug.'.$name],
1088
            $this->parameterResolver->resolveValidationGroups($resource)
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 1080 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...
1089
        );
1090
    }
1091
1092 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...
1093
    {
1094
        $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...
1095
            ->expects($this->once())
1096
            ->method('getMasterRequest')
1097
            ->will($this->returnValue($request = $this->createRequestMock()));
1098
1099
        $resource = $this->createResourceMock();
1100
        $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...
1101
            ->expects($this->once())
1102
            ->method('getName')
1103
            ->will($this->returnValue($name = 'name'));
1104
1105
        $request->attributes
1106
            ->expects($this->once())
1107
            ->method('get')
1108
            ->with(
1109
                $this->identicalTo('_lug_validation_groups'),
1110
                $this->identicalTo($groups = [Constraint::DEFAULT_GROUP, 'lug.'.$name])
1111
            )
1112
            ->will($this->returnValue($groups));
1113
1114
        $this->assertSame($groups, $this->parameterResolver->resolveValidationGroups($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 1099 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...
1115
    }
1116
1117 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...
1118
    {
1119
        $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...
1120
            ->expects($this->once())
1121
            ->method('getMasterRequest')
1122
            ->will($this->returnValue($request = $this->createRequestMock()));
1123
1124
        $resource = $this->createResourceMock();
1125
        $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...
1126
            ->expects($this->once())
1127
            ->method('getName')
1128
            ->will($this->returnValue($name = 'name'));
1129
1130
        $request->attributes
1131
            ->expects($this->once())
1132
            ->method('get')
1133
            ->with(
1134
                $this->identicalTo('_lug_validation_groups'),
1135
                $this->identicalTo([Constraint::DEFAULT_GROUP, 'lug.'.$name])
1136
            )
1137
            ->will($this->returnValue($groups = ['group']));
1138
1139
        $this->assertSame($groups, $this->parameterResolver->resolveValidationGroups($resource));
0 ignored issues
show
Bug introduced by
It seems like $resource defined by $this->createResourceMock() on line 1124 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...
1140
    }
1141
1142
    public function testResolveVoterWithoutRequest()
1143
    {
1144
        $this->assertFalse($this->parameterResolver->resolveVoter());
1145
    }
1146
1147
    public function testResolveVoterDefault()
1148
    {
1149
        $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...
1150
            ->expects($this->once())
1151
            ->method('getMasterRequest')
1152
            ->will($this->returnValue($request = $this->createRequestMock()));
1153
1154
        $request->attributes
1155
            ->expects($this->once())
1156
            ->method('get')
1157
            ->with($this->identicalTo('_lug_voter'), $this->identicalTo(false))
1158
            ->will($this->returnValue(false));
1159
1160
        $this->assertFalse($this->parameterResolver->resolveVoter());
1161
    }
1162
1163 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...
1164
    {
1165
        $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...
1166
            ->expects($this->once())
1167
            ->method('getMasterRequest')
1168
            ->will($this->returnValue($request = $this->createRequestMock()));
1169
1170
        $request->attributes
1171
            ->expects($this->once())
1172
            ->method('get')
1173
            ->with($this->identicalTo('_lug_voter'), $this->identicalTo(false))
1174
            ->will($this->returnValue(true));
1175
1176
        $this->assertTrue($this->parameterResolver->resolveVoter());
1177
    }
1178
1179
    /**
1180
     * @return \PHPUnit_Framework_MockObject_MockObject|RequestStack
1181
     */
1182
    private function createRequestStackMock()
1183
    {
1184
        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...
1185
    }
1186
1187
    /**
1188
     * @return \PHPUnit_Framework_MockObject_MockObject|PropertyAccessorInterface
1189
     */
1190
    private function createPropertyAccessorMock()
1191
    {
1192
        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...
1193
    }
1194
1195
    /**
1196
     * @return \PHPUnit_Framework_MockObject_MockObject|Request
1197
     */
1198
    private function createRequestMock()
1199
    {
1200
        $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...
1201
        $request->attributes = $this->createParameterBagMock();
1202
1203
        return $request;
1204
    }
1205
1206
    /**
1207
     * @return \PHPUnit_Framework_MockObject_MockObject|ParameterBag
1208
     */
1209
    private function createParameterBagMock()
1210
    {
1211
        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...
1212
    }
1213
1214
    /**
1215
     * @return \PHPUnit_Framework_MockObject_MockObject|ResourceInterface
1216
     */
1217
    private function createResourceMock()
1218
    {
1219
        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...
1220
    }
1221
}
1222