8000 [DoctrineBridge] Load refreshed user proxy by MatTheCat · Pull Request #50813 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] Load refreshed user proxy #50813

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

Merged
merged 1 commit into from
Jul 7, 2023
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
[DoctrineBridge] Load refreshed user proxy
  • Loading branch information
MatTheCat committed Jun 28, 2023
commit 6f53d545d18a1c777a924484f02ab04feaa6815c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\Persistence\Mapping\ClassMetadata;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use Doctrine\Persistence\Proxy;
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
Expand Down Expand Up @@ -117,6 +118,10 @@ public function refreshUser(UserInterface $user)
}
}

if ($refreshedUser instanceof Proxy && !$refreshedUser->__isInitialized()) {
$refreshedUser->__load();
}

return $refreshedUser;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use Doctrine\Persistence\ObjectRepository;
use Doctrine\Persistence\Proxy;
use PHPUnit\Framework\TestCase;
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
Expand Down Expand Up @@ -197,6 +198,27 @@ public function testPasswordUpgrades()
$provider->upgradePassword($user, 'foobar');
}

public function testRefreshedUserProxyIsLoaded()
{
$em = DoctrineTestHelper::createTestEntityManager();
$this->createSchema($em);

$user = new User(1, 1, 'user1');

$em->persist($user);
$em->flush();
$em->clear();

// store a proxy in the identity map
$em->getReference(User::class, ['id1' => 1, 'id2' => 1]);

$provider = new EntityUserProvider($this->getManager($em), User::class);
$refreshedUser = $provider->refreshUser($user);

$this->assertInstanceOf(Proxy::class, $refreshedUser);
$this->assertTrue($refreshedUser->__isInitialized());
}

private function getManager($em, $name = null)
{
$manager = $this->createMock(ManagerRegistry::class);
Expand Down
0