@@ -394,52 +394,28 @@ public function getCredentials()
394
394
HttpKernelInterface::MASTER_REQUEST
395
395
),
396
396
$ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
397
- new class () extends AbstractToken {
398
- public function __construct ()
397
+ new MockToken ( new class () extends MockUser {
398
+ public function getUsername (): string
399
399
{
400
- parent ::__construct ();
401
-
402
- $ this ->setAuthenticated (true );
403
- $ this ->setUser (new class () implements UserInterface {
404
- public function getRoles ()
405
- {
406
- return [];
407
- }
408
-
409
- public function getPassword ()
410
- {
411
- return null ;
412
- }
413
-
414
- public function getSalt ()
415
- {
416
- return null ;
417
- }
418
-
419
- public function getUsername (): string
420
- {
421
- return $ this ->getUserIdentifier ();
422
- }
423
-
424
- public function getUserIdentifier (): string
425
- {
426
- return 'foo_user ' ;
427
- }
428
-
429
- public function eraseCredentials (): void
430
- {
431
- }
432
- });
400
+ return $ this ->getUserIdentifier ();
433
401
}
434
-
435
- public function getCredentials ()
436
- {
437
- return null ;
438
- }
439
- },
402
+ }),
440
403
new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
441
404
];
442
405
406
+ if (Kernel::VERSION_ID >= 503000 ) {
407
+ yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface WITHOUT getUsername ' => [
408
+ new RequestEvent (
409
+ $ this ->createMock (HttpKernelInterface::class),
410
+ new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
411
+ HttpKernelInterface::MASTER_REQUEST
412
+ ),
413
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
414
+ new MockToken (new class () extends MockUser {}),
415
+ new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
416
+ ];
417
+ }
418
+
443
419
yield 'token.authenticated = TRUE && token.user INSTANCEOF object && __toString() method EXISTS ' => [
444
420
new RequestEvent (
445
421
$ this ->createMock (HttpKernelInterface::class),
@@ -594,3 +570,46 @@ private function getMockedClientWithOptions(Options $options): ClientInterface
594
570
return $ client ;
595
571
}
596
572
}
573
+
574
+ class MockToken extends AbstractToken
575
+ {
576
+ public function __construct (UserInterface $ user )
577
+ {
578
+ parent ::__construct ();
579
+
580
+ $ this ->setAuthenticated (true );
581
+ $ this ->setUser ($ user );
582
+ }
583
+
584
+ public function getCredentials (): ?string
585
+ {
586
+ return null ;
587
+ }
588
+ }
589
+
590
+ abstract class MockUser implements UserInterface
591
+ {
592
+ public function getUserIdentifier (): string
593
+ {
594
+ return 'foo_user ' ;
595
+ }
596
+
597
+ public function getRoles ()
598
+ {
599
+ return [];
600
+ }
601
+
602
+ public function getPassword ()
603
+ {
604
+ return 'fake-pw ' ;
605
+ }
606
+
607
+ public function getSalt ()
608
+ {
609
+ return 'fake-salt ' ;
610
+ }
611
+
612
+ public function eraseCredentials (): void
613
+ {
614
+ }
615
+ }
0 commit comments