@@ -134,7 +134,9 @@ public function __construct()
134
134
{
135
135
parent ::__construct ();
136
136
137
- $ this ->setAuthenticated (false );
137
+ if (method_exists ($ this , 'setAuthenticated ' )) {
138
+ $ this ->setAuthenticated (false );
139
+ }
138
140
}
139
141
140
142
public function getCredentials ()
@@ -157,7 +159,9 @@ public function __construct()
157
159
{
158
160
parent ::__construct ();
159
161
160
- $ this ->setAuthenticated (true );
162
+ if (method_exists ($ this , 'setAuthenticated ' )) {
163
+ $ this ->setAuthenticated (true );
164
+ }
161
165
}
162
166
163
167
public function getCredentials ()
@@ -180,7 +184,9 @@ public function __construct()
180
184
{
181
185
parent ::__construct ();
182
186
183
- $ this ->setAuthenticated (true );
187
+ if (method_exists ($ this , 'setAuthenticated ' )) {
188
+ $ this ->setAuthenticated (true );
189
+ }
184
190
$ this ->setUser ('foo_user ' );
185
191
}
186
192
@@ -204,7 +210,9 @@ public function __construct()
204
210
{
205
211
parent ::__construct ();
206
212
207
- $ this ->setAuthenticated (true );
213
+ if (method_exists ($ this , 'setAuthenticated ' )) {
214
+ $ this ->setAuthenticated (true );
215
+ }
208
216
$ this ->setUser (new class () extends UserStub {
209
217
public function getUserIdentifier (): string
210
218
{
@@ -233,7 +241,10 @@ public function __construct()
233
241
{
234
242
parent ::__construct ();
235
243
236
- $ this ->setAuthenticated (true );
244
+ if (method_exists ($ this , 'setAuthenticated ' )) {
245
+ $ this ->setAuthenticated (true );
246
+ }
247
+
237
248
$ this ->setUser (new class () implements \Stringable {
238
249
public function __toString (): string
239
250
{
@@ -305,7 +316,9 @@ public function __construct()
305
316
{
306
317
parent ::__construct ();
307
318
308
- $ this ->setAuthenticated (false );
319
+ if (method_exists ($ this , 'setAuthenticated ' )) {
320
+ $ this ->setAuthenticated (false );
321
+ }
309
322
}
310
323
311
324
public function getCredentials ()
@@ -328,7 +341,9 @@ public function __construct()
328
341
{
329
342
parent ::__construct ();
330
343
331
- $ this ->setAuthenticated (true );
344
+ if (method_exists ($ this , 'setAuthenticated ' )) {
345
+ $ this ->setAuthenticated (true );
346
+ }
332
347
}
333
348
334
349
public function getCredentials ()
@@ -339,29 +354,32 @@ public function getCredentials()
339
354
UserDataBag::createFromUserIpAddress ('127.0.0.1 ' ),
340
355
];
341
356
342
- yield 'token.authenticated = TRUE && token.user INSTANCEOF string ' => [
343
- new RequestEvent (
344
- $ this ->createMock (HttpKernelInterface::class),
345
- new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
346
- HttpKernelInterface::MASTER_REQUEST
347
- ),
348
- $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
349
- new class () extends AbstractToken {
350
- public function __construct ()
351
- {
352
- parent ::__construct ();
357
+ if (Kernel::VERSION_ID < 60000 ) {
358
+ yield 'token.authenticated = TRUE && token.user INSTANCEOF string ' => [
359
+ new RequestEvent (
360
+ $ this ->createMock (HttpKernelInterface::class),
361
+ new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
362
+ HttpKernelInterface::MASTER_REQUEST
363
+ ),
364
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
365
+ new class () extends AbstractToken {
366
+ public function __construct ()
367
+ {
368
+ parent ::__construct ();
353
369
354
- $ this ->setAuthenticated (true );
355
- $ this ->setUser ('foo_user ' );
356
- }
370
+ $ this ->setAuthenticated (true );
357
371
358
- public function getCredentials ()
359
- {
360
- return null ;
361
- }
362
- },
363
- new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
364
- ];
372
+ $ this ->setUser ('foo_user ' );
373
+ }
374
+
375
+ public function getCredentials ()
376
+ {
377
+ return null ;
378
+ }
379
+ },
380
+ new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
381
+ ];
382
+ }
365
383
366
384
yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method DOES NOT EXISTS ' => [
367
385
new RequestEvent (
@@ -392,34 +410,39 @@ public function getUserIdentifier(): string
392
410
];
393
411
}
394
412
395
- yield 'token.authenticated = TRUE && token.user INSTANCEOF object && __toString() method EXISTS ' => [
396
- new RequestEvent (
397
- $ this ->createMock (HttpKernelInterface::class),
398
- new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
399
- HttpKernelInterface::MASTER_REQUEST
400
- ),
401
- $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
402
- new class () extends AbstractToken {
403
- public function __construct ()
404
- {
405
- parent ::__construct ();
413
+ if (Kernel::VERSION_ID < 60000 ) {
414
+ yield 'token.authenticated = TRUE && token.user INSTANCEOF object && __toString() method EXISTS ' => [
415
+ new RequestEvent (
416
+ $ this ->createMock (HttpKernelInterface::class),
417
+ new Request ([], [], [], [], [], ['REMOTE_ADDR ' => '127.0.0.1 ' ]),
418
+ HttpKernelInterface::MASTER_REQUEST
419
+ ),
420
+ $ this ->getMockedClientWithOptions (new Options (['send_default_pii ' => true ])),
421
+ new class () extends AbstractToken {
422
+ public function __construct ()
423
+ {
424
+ parent ::__construct ();
406
425
407
- $ this ->setAuthenticated (true );
408
- $ this ->setUser (new class () implements \Stringable {
409
- public function __toString (): string
410
- {
411
- return 'foo_user ' ;
426
+ if (method_exists ($ this , 'setAuthenticated ' )) {
427
+ $ this ->setAuthenticated (true );
412
428
}
413
- });
414
- }
415
429
416
- public function getCredentials ()
417
- {
418
- return null ;
419
- }
420
- },
421
- new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
422
- ];
430
+ $ this ->setUser (new class () implements \Stringable {
431
+ public function __toString (): string
432
+ {
433
+ return 'foo_user ' ;
434
+ }
435
+ });
436
+ }
437
+
438
+ public function getCredentials ()
439
+ {
440
+ return null ;
441
+ }
442
+ },
443
+ new UserDataBag (null , null , '127.0.0.1 ' , 'foo_user ' ),
444
+ ];
445
+ }
423
446
424
447
yield 'request.clientIp IS NULL ' => [
425
448
new RequestEvent (
@@ -564,7 +587,10 @@ public function __construct(UserInterface $user)
564
587
{
565
588
parent ::__construct ();
566
589
567
- $ this ->setAuthenticated (true );
590
+ if (method_exists ($ this , 'setAuthenticated ' )) {
591
+ $ this ->setAuthenticated (true );
592
+ }
593
+
568
594
$ this ->setUser ($ user );
569
595
}
570
596
@@ -581,6 +607,11 @@ public function getUsername(): string
581
607
return 'foo_user ' ;
582
608
}
583
609
610
+ public function getUserIdentifier (): string
611
+ {
612
+ return 'foo_user ' ;
613
+ }
614
+
584
615
public function getRoles (): array
585
616
{
586
617
return [];
0 commit comments