Skip to content

Fix broken build after reintroduction of the getUsername() method in Symfony 5.3.1 #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 19 additions & 43 deletions tests/EventListener/RequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,34 +205,10 @@ public function __construct()
parent::__construct();

$this->setAuthenticated(true);
$this->setUser(new class() implements UserInterface {
public function getRoles()
{
return [];
}

public function getPassword()
{
return null;
}

public function getSalt()
{
return null;
}

public function getUsername(): string
{
return $this->getUserIdentifier();
}

$this->setUser(new class() extends UserStub {
public function getUserIdentifier(): string
{
return 'foo_user';
}

public function eraseCredentials(): void
{
return $this->getUsername();
}
});
}
Expand Down Expand Up @@ -387,31 +363,31 @@ public function getCredentials()
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
];

yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface' => [
yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method DOES NOT EXISTS' => [
new RequestEvent(
$this->createMock(HttpKernelInterface::class),
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
HttpKernelInterface::MASTER_REQUEST
),
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
new MockToken(new class() extends MockUser {
public function getUsername(): string
{
return $this->getUserIdentifier();
}
}),
new TokenStub(new class() extends UserStub {}),
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
];

if (Kernel::VERSION_ID >= 503000) {
yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface WITHOUT getUsername' => [
yield 'token.authenticated = TRUE && token.user INSTANCEOF UserInterface && getUserIdentifier() method EXISTS' => [
new RequestEvent(
$this->createMock(HttpKernelInterface::class),
new Request([], [], [], [], [], ['REMOTE_ADDR' => '127.0.0.1']),
HttpKernelInterface::MASTER_REQUEST
),
$this->getMockedClientWithOptions(new Options(['send_default_pii' => true])),
new MockToken(new class() extends MockUser {}),
new TokenStub(new class() extends UserStub {
public function getUserIdentifier(): string
{
return $this->getUsername();
}
}),
new UserDataBag(null, null, '127.0.0.1', 'foo_user'),
];
}
Expand Down Expand Up @@ -571,7 +547,7 @@ private function getMockedClientWithOptions(Options $options): ClientInterface
}
}

class MockToken extends AbstractToken
final class TokenStub extends AbstractToken
{
public function __construct(UserInterface $user)
{
Expand All @@ -587,26 +563,26 @@ public function getCredentials(): ?string
}
}

abstract class MockUser implements UserInterface
abstract class UserStub implements UserInterface
{
public function getUserIdentifier(): string
public function getUsername(): string
{
return 'foo_user';
}

public function getRoles()
public function getRoles(): array
{
return [];
}

public function getPassword()
public function getPassword(): ?string
{
return 'fake-pw';
return null;
}

public function getSalt()
public function getSalt(): ?string
{
return 'fake-salt';
return null;
}

public function eraseCredentials(): void
Expand Down