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

fix: #31 registery does not match doctrine proxies #33

Merged
merged 1 commit into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Mixpanel/Security/UserData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
49 changes: 47 additions & 2 deletions spec/Gordalina/MixpanelBundle/Mixpanel/Security/UserDataSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
{
}