From cfa9112c30e22f7322bbc33e2b4737d31e8e8c95 Mon Sep 17 00:00:00 2001 From: Alexander Kim Date: Tue, 22 Nov 2022 10:07:40 -0500 Subject: [PATCH] fix: #31 registery does not match doctrine proxies --- Mixpanel/Security/UserData.php | 2 +- .../Mixpanel/Security/UserDataSpec.php | 49 ++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/Mixpanel/Security/UserData.php b/Mixpanel/Security/UserData.php index f6bff9b..2028541 100644 --- a/Mixpanel/Security/UserData.php +++ b/Mixpanel/Security/UserData.php @@ -105,7 +105,7 @@ public function getProperties($instance = null) } foreach ($this->registry->getUsers() as $class => $properties) { - if ($className !== $class) { + if (!is_a($className, $class, true)) { continue; } diff --git a/spec/Gordalina/MixpanelBundle/Mixpanel/Security/UserDataSpec.php b/spec/Gordalina/MixpanelBundle/Mixpanel/Security/UserDataSpec.php index 354106d..ac6f4e0 100644 --- a/spec/Gordalina/MixpanelBundle/Mixpanel/Security/UserDataSpec.php +++ b/spec/Gordalina/MixpanelBundle/Mixpanel/Security/UserDataSpec.php @@ -8,6 +8,7 @@ use PhpSpec\ObjectBehavior; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Symfony\Component\Security\Core\Authentication\Token\TokenInterface; +use Symfony\Component\Security\Core\User\UserInterface; class UserDataSpec extends ObjectBehavior { @@ -25,11 +26,55 @@ public function it_should_return_empty_properties_when_user_is_anonymous( TokenStorageInterface $tokenStorage, TokenInterface $token ) { + $token->getUser()->willReturn(null); $tokenStorage->getToken()->willReturn($token); - $token->getUser()->willReturn(null); - $this->getProperties()->shouldReturn([]); } + + public function it_should_return_properties_for_proxies( + TokenStorageInterface $tokenStorage, + TokenInterface $token, + ManagerRegistry $registry + ) { + $registry->getUsers()->willReturn([TestUser::class => [ + 'id' => 'id', + ]]); + + $user = new TestUserProxy(); + + $token->getUser()->willReturn($user); + + $tokenStorage->getToken()->willReturn($token); + + $this->getProperties()->shouldReturn(['id' => '1']); + } +} + +class TestUser implements UserInterface +{ + public function getRoles(): array + { + return []; + } + + public function eraseCredentials(): void + { + return; + } + + public function getUserIdentifier(): string + { + return '1'; + } + + public function getId(): string + { + return $this->getUserIdentifier(); + } +} + +class TestUserProxy extends TestUser +{ }