Skip to content

Commit

Permalink
Merge pull request #1106 from nicolas-grekas/fix-reset
Browse files Browse the repository at this point in the history
Skip resetting managers when proxy-manager is not installed
  • Loading branch information
alcaeus authored Dec 18, 2019
2 parents f7f32a3 + bc3db73 commit 5d477e6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
6 changes: 6 additions & 0 deletions Registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

use Doctrine\ORM\EntityManager;
use Doctrine\ORM\ORMException;
use ProxyManager\Proxy\LazyLoadingInterface;
use Psr\Container\ContainerInterface;
use Symfony\Bridge\Doctrine\ManagerRegistry;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Contracts\Service\ResetInterface;
use function interface_exists;

/**
* References all Doctrine connections and entity managers in a given Container.
Expand Down Expand Up @@ -168,6 +170,10 @@ public function getEntityManagerForClass($class)

public function reset() : void
{
if (! interface_exists(LazyLoadingInterface::class)) {
return;
}

foreach (array_keys($this->getManagerNames()) as $managerName) {
$this->resetManager($managerName);
}
Expand Down
8 changes: 2 additions & 6 deletions Tests/RegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"require-dev": {
"doctrine/coding-standard": "^6.0",
"doctrine/orm": "^2.6",
"ocramius/proxy-manager": "^2.1",
"php-coveralls/php-coveralls": "^2.1",
"phpunit/phpunit": "^7.5",
"symfony/phpunit-bridge": "^4.2",
Expand Down

0 comments on commit 5d477e6

Please sign in to comment.