Skip to content

Commit 3550dde

Browse files
committed
[DoctrineBridge] Load refreshed user proxy
1 parent 708ed45 commit 3550dde

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

Security/User/EntityUserProvider.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\Persistence\Mapping\ClassMetadata;
1616
use Doctrine\Persistence\ObjectManager;
1717
use Doctrine\Persistence\ObjectRepository;
18+
use Doctrine\Persistence\Proxy;
1819
use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
1920
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
2021
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
@@ -117,6 +118,10 @@ public function refreshUser(UserInterface $user)
117118
}
118119
}
119120

121+
if ($refreshedUser instanceof Proxy && !$refreshedUser->__isInitialized()) {
122+
$refreshedUser->__load();
123+
}
124+
120125
return $refreshedUser;
121126
}
122127

Tests/Security/User/EntityUserProviderTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Doctrine\Persistence\ManagerRegistry;
1717
use Doctrine\Persistence\ObjectManager;
1818
use Doctrine\Persistence\ObjectRepository;
19+
use Doctrine\Persistence\Proxy;
1920
use PHPUnit\Framework\TestCase;
2021
use Symfony\Bridge\Doctrine\Security\User\EntityUserProvider;
2122
use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
@@ -197,6 +198,27 @@ public function testPasswordUpgrades()
197198
$provider->upgradePassword($user, 'foobar');
198199
}
199200

201+
public function testRefreshedUserProxyIsLoaded()
202+
{
203+
$em = DoctrineTestHelper::createTestEntityManager();
204+
$this->createSchema($em);
205+
206+
$user = new User(1, 1, 'user1');
207+
208+
$em->persist($user);
209+
$em->flush();
210+
$em->clear();
211+
212+
// store a proxy in the identity map
213+
$em->getReference(User::class, ['id1' => 1, 'id2' => 1]);
214+
215+
$provider = new EntityUserProvider($this->getManager($em), User::class);
216+
$refreshedUser = $provider->refreshUser($user);
217+
218+
$this->assertInstanceOf(Proxy::class, $refreshedUser);
219+
$this->assertTrue($refreshedUser->__isInitialized());
220+
}
221+
200222
private function getManager($em, $name = null)
201223
{
202224
$manager = $this->createMock(ManagerRegistry::class);

0 commit comments

Comments
 (0)