Skip to content

Commit 8e2d59a

Browse files
Merge branch '5.4' into 6.2
* 5.4: [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s [Intl] fix test [Intl] Use VarExporter::export() in PhpBundleWriter Use triggering class to generate baseline for deprecation messages from DebugClassLoader [Security] Fix false-string handling in RememberMeAuthenticator [CssSelector] Tests on Xpath translator will always pass [Serializer] Fix Normalizer not utilizing converted name for index variadic param [DepdencyInjection] Fix costly logic when checking errored definitions fix children cond [DoctrineBridge] Load refreshed user proxy [DependencyInjection] Don't ignore attributes on the actual decorator [FrameworkBundle] Prevent `cache:clear` to lose files on subsequent runs
2 parents 843493b + 3550dde commit 8e2d59a

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;
@@ -97,6 +98,10 @@ public function refreshUser(UserInterface $user): UserInterface
9798
}
9899
}
99100

101+
if ($refreshedUser instanceof Proxy && !$refreshedUser->__isInitialized()) {
102+
$refreshedUser->__load();
103+
}
104+
100105
return $refreshedUser;
101106
}
102107

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)