bugsnag / bugsnag-symfony

BugSnag notifier for the Symfony PHP framework. Monitor and report errors in your Symfony apps.
https://docs.bugsnag.com/platforms/php/symfony
MIT License
43 stars 21 forks source link

Call `getUserIdentifier` instead of `getUsername` on Symfony 6 #145

Closed imjoehaines closed 2 years ago

imjoehaines commented 2 years ago

Goal

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

https://github.com/bugsnag/bugsnag-symfony/blob/d094e0e247bfedcd8877f4a864105ec8cede26b8/DependencyInjection/ClientFactory.php#L391-L393

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 https://github.com/bugsnag/bugsnag-symfony/issues/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