Skip to content

Commit 04f96f3

Browse files
authored
Update RequestListenerTest.php
changed tests to reflect removed AuthorizationChecker
1 parent 7afae69 commit 04f96f3

File tree

1 file changed

+8
-75
lines changed

1 file changed

+8
-75
lines changed

test/EventListener/RequestListenerTest.php

Lines changed: 8 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
1717
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
1818
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
19-
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
20-
use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
2119
use Symfony\Component\Security\Core\User\UserInterface;
2220

2321
class RequestListenerTest extends TestCase
@@ -59,7 +57,6 @@ protected function setUp()
5957
public function testOnKernelRequestUserDataIsSetToScope($user): void
6058
{
6159
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
62-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
6360
$event = $this->prophesize(GetResponseEvent::class);
6461
$request = $this->prophesize(Request::class);
6562
$token = $this->prophesize(TokenInterface::class);
@@ -72,8 +69,6 @@ public function testOnKernelRequestUserDataIsSetToScope($user): void
7269

7370
$token->isAuthenticated()
7471
->willReturn(true);
75-
$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
76-
->willReturn(true);
7772

7873
$token->getUser()
7974
->willReturn($user);
@@ -113,7 +108,6 @@ public function userDataProvider(): \Generator
113108
public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
114109
{
115110
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
116-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
117111
$event = $this->prophesize(GetResponseEvent::class);
118112

119113
$event->isMasterRequest()
@@ -126,8 +120,7 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
126120

127121
$listener = new RequestListener(
128122
$this->currentHub->reveal(),
129-
$tokenStorage->reveal(),
130-
$authorizationChecker->reveal()
123+
$tokenStorage->reveal()
131124
);
132125

133126
$listener->onKernelRequest($event->reveal());
@@ -138,7 +131,6 @@ public function testOnKernelRequestUserDataIsNotSetIfSendPiiIsDisabled(): void
138131
public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
139132
{
140133
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
141-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
142134
$event = $this->prophesize(GetResponseEvent::class);
143135

144136
$event->isMasterRequest()
@@ -151,8 +143,7 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
151143

152144
$listener = new RequestListener(
153145
$this->currentHub->reveal(),
154-
$tokenStorage->reveal(),
155-
$authorizationChecker->reveal()
146+
$tokenStorage->reveal()
156147
);
157148

158149
$listener->onKernelRequest($event->reveal());
@@ -162,55 +153,19 @@ public function testOnKernelRequestUserDataIsNotSetIfNoClientIsPresent(): void
162153

163154
public function testOnKernelRequestUsernameIsNotSetIfTokenStorageIsAbsent(): void
164155
{
165-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
166-
$event = $this->prophesize(GetResponseEvent::class);
167-
$request = $this->prophesize(Request::class);
168-
169-
$event->isMasterRequest()
170-
->willReturn(true);
171-
172-
$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
173-
->shouldNotBeCalled();
174-
175-
$event->getRequest()
176-
->willReturn($request->reveal());
177-
$request->getClientIp()
178-
->willReturn('1.2.3.4');
179-
180-
$listener = new RequestListener(
181-
$this->currentHub->reveal(),
182-
null,
183-
$authorizationChecker->reveal()
184-
);
185-
186-
$listener->onKernelRequest($event->reveal());
187-
188-
$expectedUserData = [
189-
'ip_address' => '1.2.3.4',
190-
];
191-
$this->assertEquals($expectedUserData, $this->getUserContext($this->currentScope));
192-
}
193-
194-
public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsent(): void
195-
{
196-
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
197156
$event = $this->prophesize(GetResponseEvent::class);
198157
$request = $this->prophesize(Request::class);
199158

200159
$event->isMasterRequest()
201160
->willReturn(true);
202161

203-
$tokenStorage->getToken()
204-
->willReturn($this->prophesize(TokenInterface::class)->reveal());
205-
206162
$event->getRequest()
207163
->willReturn($request->reveal());
208164
$request->getClientIp()
209165
->willReturn('1.2.3.4');
210166

211167
$listener = new RequestListener(
212168
$this->currentHub->reveal(),
213-
$tokenStorage->reveal(),
214169
null
215170
);
216171

@@ -225,7 +180,6 @@ public function testOnKernelRequestUsernameIsNotSetIfAuthorizationCheckerIsAbsen
225180
public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
226181
{
227182
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
228-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
229183
$event = $this->prophesize(GetResponseEvent::class);
230184
$request = $this->prophesize(Request::class);
231185

@@ -235,18 +189,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
235189
$tokenStorage->getToken()
236190
->willReturn(null);
237191

238-
$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
239-
->shouldNotBeCalled();
240-
241192
$event->getRequest()
242193
->willReturn($request->reveal());
243194
$request->getClientIp()
244195
->willReturn('1.2.3.4');
245196

246197
$listener = new RequestListener(
247198
$this->currentHub->reveal(),
248-
$tokenStorage->reveal(),
249-
$authorizationChecker->reveal()
199+
$tokenStorage->reveal()
250200
);
251201

252202
$listener->onKernelRequest($event->reveal());
@@ -263,7 +213,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsAbsent(): void
263213
public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated(): void
264214
{
265215
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
266-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
267216
$token = $this->prophesize(TokenInterface::class);
268217
$event = $this->prophesize(GetResponseEvent::class);
269218
$request = $this->prophesize(Request::class);
@@ -277,18 +226,14 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
277226
$token->isAuthenticated()
278227
->willReturn(false);
279228

280-
$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
281-
->shouldNotBeCalled();
282-
283229
$event->getRequest()
284230
->willReturn($request->reveal());
285231
$request->getClientIp()
286232
->willReturn('1.2.3.4');
287233

288234
$listener = new RequestListener(
289235
$this->currentHub->reveal(),
290-
$tokenStorage->reveal(),
291-
$authorizationChecker->reveal()
236+
$tokenStorage->reveal()
292237
);
293238

294239
$listener->onKernelRequest($event->reveal());
@@ -302,7 +247,6 @@ public function testOnKernelRequestUsernameIsNotSetIfTokenIsNotAuthenticated():
302247
public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
303248
{
304249
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
305-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
306250
$event = $this->prophesize(GetResponseEvent::class);
307251
$request = $this->prophesize(Request::class);
308252

@@ -312,18 +256,14 @@ public function testOnKernelRequestUsernameIsNotSetIfUserIsNotRemembered(): void
312256
$tokenStorage->getToken()
313257
->willReturn(null);
314258

315-
$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
316-
->willReturn(false);
317-
318259
$event->getRequest()
319260
->willReturn($request->reveal());
320261
$request->getClientIp()
321262
->willReturn('1.2.3.4');
322263

323264
$listener = new RequestListener(
324265
$this->currentHub->reveal(),
325-
$tokenStorage->reveal(),
326-
$authorizationChecker->reveal()
266+
$tokenStorage->reveal()
327267
);
328268

329269
$listener->onKernelRequest($event->reveal());
@@ -347,8 +287,7 @@ public function testOnKernelControllerAddsRouteTag(): void
347287

348288
$listener = new RequestListener(
349289
$this->currentHub->reveal(),
350-
$this->prophesize(TokenStorageInterface::class)->reveal(),
351-
$this->prophesize(AuthorizationCheckerInterface::class)->reveal()
290+
$this->prophesize(TokenStorageInterface::class)->reveal()
352291
);
353292

354293
$listener->onKernelController($event->reveal());
@@ -371,8 +310,7 @@ public function testOnKernelControllerRouteTagIsNotSetIfRequestDoesNotHaveARoute
371310

372311
$listener = new RequestListener(
373312
$this->currentHub->reveal(),
374-
$this->prophesize(TokenStorageInterface::class)->reveal(),
375-
$this->prophesize(AuthorizationCheckerInterface::class)->reveal()
313+
$this->prophesize(TokenStorageInterface::class)->reveal()
376314
);
377315

378316
$listener->onKernelController($event->reveal());
@@ -384,7 +322,6 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
384322
->shouldNotBeCalled();
385323

386324
$tokenStorage = $this->prophesize(TokenStorageInterface::class);
387-
$authorizationChecker = $this->prophesize(AuthorizationCheckerInterface::class);
388325
$event = $this->prophesize(GetResponseEvent::class);
389326

390327
$event->isMasterRequest()
@@ -393,13 +330,9 @@ public function testOnKernelRequestUserDataAndTagsAreNotSetInSubRequest(): void
393330
$tokenStorage->getToken()
394331
->shouldNotBeCalled();
395332

396-
$authorizationChecker->isGranted(AuthenticatedVoter::IS_AUTHENTICATED_REMEMBERED)
397-
->shouldNotBeCalled();
398-
399333
$listener = new RequestListener(
400334
$this->currentHub->reveal(),
401-
$tokenStorage->reveal(),
402-
$authorizationChecker->reveal()
335+
$tokenStorage->reveal()
403336
);
404337

405338
$listener->onKernelRequest($event->reveal());

0 commit comments

Comments
 (0)