Skip to content

Commit

Permalink
Merge pull request #33 from nesl247/fix-31
Browse files Browse the repository at this point in the history
fix: #31 registery does not match doctrine proxies
  • Loading branch information
gordalina authored Dec 6, 2022
2 parents e065aa4 + cfa9112 commit c0a4534
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 3 deletions.
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
{
}

0 comments on commit c0a4534

Please sign in to comment.