diff --git a/Registry.php b/Registry.php index 0b943e4d3..19034aca6 100644 --- a/Registry.php +++ b/Registry.php @@ -3,9 +3,11 @@ namespace Doctrine\Bundle\DoctrineBundle; use Doctrine\ORM\ORMException; +use ProxyManager\Proxy\LazyLoadingInterface; use Psr\Container\ContainerInterface; use Symfony\Bridge\Doctrine\ManagerRegistry; use Symfony\Contracts\Service\ResetInterface; +use function interface_exists; /** * References all Doctrine connections and entity managers in a given Container. @@ -50,6 +52,10 @@ public function getAliasNamespace($alias) public function reset() : void { + if (! interface_exists(LazyLoadingInterface::class)) { + return; + } + foreach (array_keys($this->getManagerNames()) as $managerName) { $this->resetManager($managerName); } diff --git a/Tests/RegistryTest.php b/Tests/RegistryTest.php index 89ebb7dda..a2eccabcd 100644 --- a/Tests/RegistryTest.php +++ b/Tests/RegistryTest.php @@ -123,17 +123,13 @@ public function testResetUnknownEntityManager() $registry->resetManager('default'); } - /** - * @group legacy - */ public function testReset() { - $em = new stdClass(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container->expects($this->once()) - ->method('get') + ->method('initialized') ->with($this->equalTo('doctrine.orm.default_entity_manager')) - ->will($this->returnValue($em)); + ->will($this->returnValue(false)); $registry = new Registry($container, [], ['default' => 'doctrine.orm.default_entity_manager'], 'default', 'default'); $registry->reset(); diff --git a/composer.json b/composer.json index 88d593ce9..bed6ef9d8 100644 --- a/composer.json +++ b/composer.json @@ -40,6 +40,7 @@ "require-dev": { "doctrine/coding-standard": "^6.0", "doctrine/orm": "^2.6", + "ocramius/proxy-manager": "^2.1", "phpunit/phpunit": "^7.5", "symfony/phpunit-bridge": "^4.2", "symfony/property-info": "^4.3.3|^5.0",