Completed
Pull Request — master (#273)
by
unknown
07:15
created

UserContextSubscriberTest::testMisconfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 8
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCacheBundle package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCacheBundle\Tests\Unit\EventListener;
13
14
use FOS\HttpCache\UserContext\HashGenerator;
15
use FOS\HttpCacheBundle\EventListener\UserContextSubscriber;
16
use Symfony\Component\HttpFoundation\Request;
17
use Symfony\Component\HttpFoundation\Response;
18
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
19
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
20
use Symfony\Component\HttpKernel\HttpKernelInterface;
21
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
22
23
class UserContextSubscriberTest extends \PHPUnit_Framework_TestCase
24
{
25
    /**
26
     * @expectedException \InvalidArgumentException
27
     */
28
    public function testMisconfiguration()
29
    {
30
        new UserContextSubscriber(
31
            \Mockery::mock('\Symfony\Component\HttpFoundation\RequestMatcherInterface'),
1 ignored issue
show
Documentation introduced by
\Mockery::mock('\\Symfon...questMatcherInterface') is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
            \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator'),
1 ignored issue
show
Documentation introduced by
\Mockery::mock('\\FOS\\H...ontext\\HashGenerator') is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
33
            array()
34
        );
35
    }
36
37 View Code Duplication
    public function testOnKernelRequest()
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...
38
    {
39
        $request = new Request();
40
        $request->setMethod('HEAD');
41
42
        $requestMatcher = $this->getRequestMatcher($request, true);
43
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
44
        $hashGenerator->shouldReceive('generateHash')->andReturn('hash');
45
46
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47
        $event = $this->getKernelRequestEvent($request);
48
49
        $userContextSubscriber->onKernelRequest($event);
50
51
        $response = $event->getResponse();
52
53
        $this->assertNotNull($response);
54
        $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
55
        $this->assertEquals('hash', $response->headers->get('X-Hash'));
56
        $this->assertNull($response->headers->get('Vary'));
57
        $this->assertEquals('max-age=0, no-cache, private', $response->headers->get('Cache-Control'));
58
    }
59
60 View Code Duplication
    public function testOnKernelRequestNonMaster()
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...
61
    {
62
        $request = new Request();
63
        $request->setMethod('HEAD');
64
65
        $requestMatcher = $this->getRequestMatcher($request, true);
66
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
67
        $hashGenerator->shouldReceive('generateHash')->never();
68
69
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
        $event = $this->getKernelRequestEvent($request, HttpKernelInterface::SUB_REQUEST);
71
72
        $userContextSubscriber->onKernelRequest($event);
73
74
        $this->assertNull($event->getResponse());
75
    }
76
77 View Code Duplication
    public function testOnKernelRequestCached()
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...
78
    {
79
        $request = new Request();
80
        $request->setMethod('HEAD');
81
82
        $requestMatcher = $this->getRequestMatcher($request, true);
83
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
84
        $hashGenerator->shouldReceive('generateHash')->andReturn('hash');
85
86
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash', 30);
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
87
        $event = $this->getKernelRequestEvent($request);
88
89
        $userContextSubscriber->onKernelRequest($event);
90
91
        $response = $event->getResponse();
92
93
        $this->assertNotNull($response);
94
        $this->assertInstanceOf('\Symfony\Component\HttpFoundation\Response', $response);
95
        $this->assertEquals('hash', $response->headers->get('X-Hash'));
96
        $this->assertEquals('X-SessionId', $response->headers->get('Vary'));
97
        $this->assertEquals('max-age=30, public', $response->headers->get('Cache-Control'));
98
    }
99
100 View Code Duplication
    public function testOnKernelRequestNotMatched()
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...
101
    {
102
        $request = new Request();
103
        $request->setMethod('HEAD');
104
105
        $requestMatcher = $this->getRequestMatcher($request, false);
106
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
107
        $hashGenerator->shouldReceive('generateHash')->andReturn('hash');
1 ignored issue
show
Unused Code introduced by
The call to MockInterface::shouldReceive() has too many arguments starting with 'generateHash'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
108
109
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
110
        $event = $this->getKernelRequestEvent($request);
111
112
        $userContextSubscriber->onKernelRequest($event);
113
114
        $response = $event->getResponse();
115
116
        $this->assertNull($response);
117
    }
118
119 View Code Duplication
    public function testOnKernelResponse()
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...
120
    {
121
        $request = new Request();
122
        $request->setMethod('HEAD');
123
        $request->headers->set('X-Hash', 'hash');
124
125
        $requestMatcher = $this->getRequestMatcher($request, false);
126
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
127
128
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
129
        $event = $this->getKernelResponseEvent($request);
130
131
        $userContextSubscriber->onKernelResponse($event);
132
133
        $this->assertContains('X-Hash', $event->getResponse()->headers->get('Vary'));
134
    }
135
136 View Code Duplication
    public function testOnKernelResponseNotMaster()
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...
137
    {
138
        $request = new Request();
139
        $request->setMethod('HEAD');
140
        $request->headers->set('X-Hash', 'hash');
141
142
        $requestMatcher = $this->getRequestMatcher($request, false);
143
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
144
145
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
146
        $event = $this->getKernelResponseEvent($request, null, HttpKernelInterface::SUB_REQUEST);
147
148
        $userContextSubscriber->onKernelResponse($event);
149
150
        $this->assertFalse($event->getResponse()->headers->has('Vary'));
151
    }
152
153
    /**
154
     * If there is no hash in the request, vary on the user identifier.
155
     */
156 View Code Duplication
    public function testOnKernelResponseNotCached()
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...
157
    {
158
        $request = new Request();
159
        $request->setMethod('HEAD');
160
161
        $requestMatcher = $this->getRequestMatcher($request, false);
162
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
163
164
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
165
        $event = $this->getKernelResponseEvent($request);
166
167
        $userContextSubscriber->onKernelResponse($event);
168
169
        $this->assertEquals('X-SessionId', $event->getResponse()->headers->get('Vary'));
170
    }
171
172
    /**
173
     * If there is no hash in the request, vary on the user identifier.
174
     */
175
    public function testFullRequestHashOk()
176
    {
177
        $request = new Request();
178
        $request->setMethod('GET');
179
        $request->headers->set('X-Hash', 'hash');
180
181
        $requestMatcher = $this->getRequestMatcher($request, false);
182
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
183
        $hashGenerator->shouldReceive('generateHash')->andReturn('hash');
1 ignored issue
show
Unused Code introduced by
The call to MockInterface::shouldReceive() has too many arguments starting with 'generateHash'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
184
185
        // onKernelRequest
186
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
187
        $event = $this->getKernelRequestEvent($request);
188
189
        $userContextSubscriber->onKernelRequest($event);
190
191
        $response = $event->getResponse();
192
193
        $this->assertNull($response);
194
195
        // onKernelResponse
196
        $event = $this->getKernelResponseEvent($request);
197
        $userContextSubscriber->onKernelResponse($event);
198
199
        $this->assertContains('X-Hash', $event->getResponse()->headers->get('Vary'));
200
    }
201
202
    /**
203
     * If there is no hash in the the requests but session changed, prevent setting bad cache
204
     */
205
    public function testFullRequestHashChanged()
206
    {
207
        $request = new Request();
208
        $request->setMethod('GET');
209
        $request->headers->set('X-Hash', 'hash');
210
211
        $requestMatcher = $this->getRequestMatcher($request, false);
212
        $hashGenerator = \Mockery::mock('\FOS\HttpCache\UserContext\HashGenerator');
213
        $hashGenerator->shouldReceive('generateHash')->andReturn('hash-changed');
1 ignored issue
show
Unused Code introduced by
The call to MockInterface::shouldReceive() has too many arguments starting with 'generateHash'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
214
215
        // onKernelRequest
216
        $userContextSubscriber = new UserContextSubscriber($requestMatcher, $hashGenerator, array('X-SessionId'), 'X-Hash');
2 ignored issues
show
Documentation introduced by
$requestMatcher is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...equestMatcherInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$hashGenerator is of type object<Mockery\MockInterface>, but the function expects a object<FOS\HttpCache\UserContext\HashGenerator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
217
        $event = $this->getKernelRequestEvent($request);
218
219
        $userContextSubscriber->onKernelRequest($event);
220
221
        $response = $event->getResponse();
222
223
        $this->assertNull($response);
224
225
        // onKernelResponse
226
        $event = $this->getKernelResponseEvent($request);
227
        $userContextSubscriber->onKernelResponse($event);
228
229
        $this->assertFalse($event->getResponse()->headers->has('Vary'));
230
        $this->assertEquals('max-age=0, no-cache, private', $event->getResponse()->headers->get('Cache-Control'));
231
    }
232
233
    protected function getKernelRequestEvent(Request $request, $type = HttpKernelInterface::MASTER_REQUEST)
234
    {
235
        return new GetResponseEvent(
236
            \Mockery::mock('\Symfony\Component\HttpKernel\HttpKernelInterface'),
1 ignored issue
show
Documentation introduced by
\Mockery::mock('\\Symfon...\\HttpKernelInterface') is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...el\HttpKernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
237
            $request,
238
            $type
239
        );
240
    }
241
242 View Code Duplication
    protected function getKernelResponseEvent(Request $request, Response $response = null, $type = HttpKernelInterface::MASTER_REQUEST)
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...
243
    {
244
        return new FilterResponseEvent(
245
            \Mockery::mock('\Symfony\Component\HttpKernel\HttpKernelInterface'),
1 ignored issue
show
Documentation introduced by
\Mockery::mock('\\Symfon...\\HttpKernelInterface') is of type object<Mockery\MockInterface>, but the function expects a object<Symfony\Component...el\HttpKernelInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
246
            $request,
247
            $type,
248
            $response ?: new Response()
249
        );
250
    }
251
252
    /**
253
     * @param Request $request
254
     * @param bool    $match
255
     *
256
     * @return \Mockery\MockInterface|RequestMatcherInterface
257
     */
258
    private function getRequestMatcher(Request $request, $match)
259
    {
260
        $requestMatcher = \Mockery::mock('\Symfony\Component\HttpFoundation\RequestMatcherInterface');
261
        $requestMatcher->shouldReceive('matches')->with($request)->andReturn($match);
262
263
        return $requestMatcher;
264
    }
265
}
266