You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #60535 [DoctrineBridge] Fix resetting the manager when using native lazy objects (HypeMC)
This PR was merged into the 7.3 branch.
Discussion
----------
[DoctrineBridge] Fix resetting the manager when using native lazy objects
| Q | A
| ------------- | ---
| Branch? | 7.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | -
| License | MIT
PR #59913 doesn't seem to work as expected. For example, a simple test like this:
```php
class DoctrineTest extends KernelTestCase
{
public function testManagerRegistryReset(): void
{
$entityManager = self::getContainer()->get(EntityManagerInterface::class);
$entityManager->close();
self::assertFalse($entityManager->isOpen());
$managerRegistry = self::getContainer()->get(ManagerRegistry::class);
$managerRegistry->resetManager();
self::assertTrue($entityManager->isOpen());
}
}
```
fails with:
> There was 1 error:
>
> 1) App\Tests\DoctrineTest::testManagerRegistryReset
> Error: Call to a member function __construct() on false
>
> /project/var/cache/test/ContainerTVZSKa5/App_KernelTestDebugContainer.php:709
> /project/vendor/symfony/doctrine-bridge/ManagerRegistry.php:91
> /project/vendor/doctrine/orm/src/EntityManager.php:534
> /project/tests/DoctrineTest.php:21
Here's the dumped container for reference:
```php
protected static function getDoctrine_Orm_DefaultEntityManagerService($container, $lazyLoad = true)
{
if (true === $lazyLoad) {
return $container->services['doctrine.orm.default_entity_manager'] = new \ReflectionClass('Doctrine\ORM\EntityManager')->newLazyGhost(static function ($proxy) use ($container) { self::getDoctrine_Orm_DefaultEntityManagerService($container, $proxy); });
}
include_once \dirname(__DIR__, 4).'/vendor/doctrine/orm/src/Proxy/Autoloader.php';
include_once \dirname(__DIR__, 4).'/vendor/doctrine/persistence/src/Persistence/ObjectManager.php';
include_once \dirname(__DIR__, 4).'/vendor/doctrine/orm/src/EntityManagerInterface.php';
include_once \dirname(__DIR__, 4).'/vendor/doctrine/orm/src/EntityManager.php';
$instance = ($lazyLoad->__construct(($container->services['doctrine.dbal.default_connection'] ?? self::getDoctrine_Dbal_DefaultConnectionService($container)), ($container->privates['doctrine.orm.default_configuration'] ?? self::getDoctrine_Orm_DefaultConfigurationService($container)), ($container->privates['doctrine.dbal.default_connection.event_manager'] ?? self::getDoctrine_Dbal_DefaultConnection_EventManagerService($container))) && false ?: $lazyLoad);
($container->privates['doctrine.orm.default_manager_configurator'] ??= new \Doctrine\Bundle\DoctrineBundle\ManagerConfigurator([], []))->configure($instance);
return $instance;
}
```
cc `@nicolas`-grekas
Commits
-------
5972d98 [DoctrineBridge] Fix resetting the manager when using native lazy objects
0 commit comments