Skip to content
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

Call getUserIdentifier instead of getUsername on Symfony 6 #145

Merged
merged 5 commits into from
Jan 17, 2022

Conversation

imjoehaines
Copy link
Member

@imjoehaines imjoehaines commented Jan 14, 2022

Goal

We automatically detect the logged in user's ID, which currently uses getUsername to fetch an identifier:

if ($user instanceof UserInterface) {
return ['id' => $user->getUsername()];
}

Symfony 5.3 deprecated getUsername and introduced getUserIdentifier to replace it. Symfony 6.0 has subsequently removed getUsername, leaving only getUserIdentifier. This causes a crash as we're calling a method that may not exist (older code bases may still implement getUsername in addition to getUserIdentifier)

See #141

Testing

I've added a Maze Runner test for our user detection logic on Symfony 4 and 6. This covers both the getUsername branch, as well as the getUserIdentifier branch

I'll add the same test setup for Symfony 2 & 5 separately, to avoid making this PR too huge

This is only running on Symfony 4 for now; other versions will be
added separately
This fixes a crash when using Symfony 6 as 'getUsername' may no longer
exist
Copy link
Contributor

@kattrali kattrali left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good - one query for futureproofing

DependencyInjection/ClientFactory.php Outdated Show resolved Hide resolved
Base automatically changed from symfony-6-maze-runner-fixture to master January 17, 2022 14:17
@imjoehaines imjoehaines changed the base branch from master to next January 17, 2022 14:18
@imjoehaines imjoehaines merged commit f1c0319 into next Jan 17, 2022
@imjoehaines imjoehaines deleted the userinterface-changes branch January 17, 2022 14:18
@imjoehaines imjoehaines mentioned this pull request Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants