Skip to content

Commit b9fbbdf

Browse files
authored
Fix broken build after reintroduction of the getUsername() method in Symfony 5.3.1 (#520)
1 parent 9bf2fe9 commit b9fbbdf

File tree

1 file changed

+19
-43
lines changed

1 file changed

+19
-43
lines changed

tests/EventListener/RequestListenerTest.php

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -205,34 +205,10 @@ public function __construct()
205205
parent::__construct();
206206

207207
$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 {
229209
public function getUserIdentifier(): string
230210
{
231-
return 'foo_user';
232-
}
233-
234-
public function eraseCredentials(): void
235-
{
211+
return $this->getUsername();
236212
}
237213
});
238214
}
@@ -387,31 +363,31 @@ public function getCredentials()
387363
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
388364
];
389365

390-
yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface' => [
366+
yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method DOES NOT EXISTS' => [
391367
new RequestEvent(
392368
$this->createMock(HttpKernelInterface::class),
393369
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
394370
HttpKernelInterface::MASTER_REQUEST
395371
),
396372
$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 {}),
403374
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
404375
];
405376

406377
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' => [
408379
new RequestEvent(
409380
$this->createMock(HttpKernelInterface::class),
410381
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
411382
HttpKernelInterface::MASTER_REQUEST
412383
),
413384
$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+
}),
415391
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
416392
];
417393
}
@@ -571,7 +547,7 @@ private function getMockedClientWithOptions(Options $options): ClientInterface
571547
}
572548
}
573549

574-
class MockToken extends AbstractToken
550+
final class TokenStub extends AbstractToken
575551
{
576552
public function __construct(UserInterface $user)
577553
{
@@ -587,26 +563,26 @@ public function getCredentials(): ?string
587563
}
588564
}
589565

590-
abstract class MockUser implements UserInterface
566+
abstract class UserStub implements UserInterface
591567
{
592-
public function getUserIdentifier(): string
568+
public function getUsername(): string
593569
{
594570
return 'foo_user';
595571
}
596572

597-
public function getRoles()
573+
public function getRoles(): array
598574
{
599575
return [];
600576
}
601577

602-
public function getPassword()
578+
public function getPassword(): ?string
603579
{
604-
return 'fake-pw';
580+
return null;
605581
}
606582

607-
public function getSalt()
583+
public function getSalt(): ?string
608584
{
609-
return 'fake-salt';
585+
return null;
610586
}
611587

612588
public function eraseCredentials(): void

0 commit comments

Comments
 (0)