@@ -205,34 +205,10 @@ public function __construct()
205
205
parent ::__construct ();
206
206
207
207
$ this ->setAuthenticated (true );
208
- $ this ->setUser (new class () implements UserInterface {
209
- public function getRoles ()
210
- {
211
- return [];
212
- }
213
-
214
- public function getPassword ()
215
- {
216
- return null ;
217
- }
218
-
219
- public function getSalt ()
220
- {
221
- return null ;
222
- }
223
-
224
- public function getUsername (): string
225
- {
226
- return $ this ->getUserIdentifier ();
227
- }
228
-
208
+ $ this ->setUser (new class () extends UserStub {
229
209
public function getUserIdentifier (): string
230
210
{
231
- return 'foo_user ' ;
232
- }
233
-
234
- public function eraseCredentials (): void
235
- {
211
+ return $ this ->getUsername ();
236
212
}
237
213
});
238
214
}
@@ -387,31 +363,31 @@ public function getCredentials()
387
363
new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
388
364
];
389
365
390
- yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface ' => [
366
+ yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method DOES NOT EXISTS ' => [
391
367
new RequestEvent (
392
368
$ this ->createMock (HttpKernelInterface::class),
393
369
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
394
370
HttpKernelInterface::MASTER_REQUEST
395
371
),
396
372
$ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
397
- new MockToken (new class () extends MockUser {
398
- public function getUsername (): string
399
- {
400
- return $ this ->getUserIdentifier ();
401
- }
402
- }),
373
+ new TokenStub (new class () extends UserStub {}),
403
374
new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
404
375
];
405
376
406
377
if (Kernel::VERSION_ID >= 503000 ) {
407
- yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface WITHOUT getUsername ' => [
378
+ yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method EXISTS ' => [
408
379
new RequestEvent (
409
380
$ this ->createMock (HttpKernelInterface::class),
410
381
new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
411
382
HttpKernelInterface::MASTER_REQUEST
412
383
),
413
384
$ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
414
- new MockToken (new class () extends MockUser {}),
385
+ new TokenStub (new class () extends UserStub {
386
+ public function getUserIdentifier (): string
387
+ {
388
+ return $ this ->getUsername ();
389
+ }
390
+ }),
415
391
new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
416
392
];
417
393
}
@@ -571,7 +547,7 @@ private function getMockedClientWithOptions(Options $options): ClientInterface
571
547
}
572
548
}
573
549
574
- class MockToken extends AbstractToken
550
+ final class TokenStub extends AbstractToken
575
551
{
576
552
public function __construct (UserInterface $ user )
577
553
{
@@ -587,26 +563,26 @@ public function getCredentials(): ?string
587
563
}
588
564
}
589
565
590
- abstract class MockUser implements UserInterface
566
+ abstract class UserStub implements UserInterface
591
567
{
592
- public function getUserIdentifier (): string
568
+ public function getUsername (): string
593
569
{
594
570
return 'foo_user ' ;
595
571
}
596
572
597
- public function getRoles ()
573
+ public function getRoles (): array
598
574
{
599
575
return [];
600
576
}
601
577
602
- public function getPassword ()
578
+ public function getPassword (): ? string
603
579
{
604
- return ' fake-pw ' ;
580
+ return null ;
605
581
}
606
582
607
- public function getSalt ()
583
+ public function getSalt (): ? string
608
584
{
609
- return ' fake-salt ' ;
585
+ return null ;
610
586
}
611
587
612
588
public function eraseCredentials (): void
0 commit comments