Skip to content
Permalink
Browse files

Remove inner orm.entityManager so it resets properly when calling Man…

…agerRegistry::resetManager
  • Loading branch information
Jakub Červenka authored and f3l1x committed Oct 29, 2019
1 parent bb0ed30 commit 6b5384e811fea6f94909ddac56c00143a779a1a1
Showing with 30 additions and 7 deletions.
  1. +4 −7 src/DI/OrmExtension.php
  2. +26 −0 tests/cases/Unit/DI/OrmExtensionTest.php
@@ -150,13 +150,10 @@ public function loadEntityManagerConfiguration(): void
}
// Entity Manager
$original = $builder->addDefinition($this->prefix('entityManager'))
->setType(DoctrineEntityManager::class)
->setFactory(DoctrineEntityManager::class . '::create', [
$builder->getDefinitionByType(Connection::class), // Nettrine/DBAL
$this->prefix('@configuration'),
])
->setAutowired(false);
$original = new Statement(DoctrineEntityManager::class . '::create', [
$builder->getDefinitionByType(Connection::class), // Nettrine/DBAL
$this->prefix('@configuration'),
]);
// Entity Manager Decorator
$builder->addDefinition($this->prefix('entityManagerDecorator'))
@@ -10,6 +10,7 @@
use Nettrine\ORM\DI\OrmAnnotationsExtension;
use Nettrine\ORM\DI\OrmExtension;
use Nettrine\ORM\EntityManagerDecorator;
use Nettrine\ORM\ManagerRegistry;
use stdClass;
use Tests\Fixtures\DummyConfiguration;
use Tests\Fixtures\DummyEntityManagerDecorator;
@@ -89,4 +90,29 @@ public function testConfigurationException(): void
}, self::class . __METHOD__);
}
public function testResetEntityManager(): void
{
$loader = new ContainerLoader(TEMP_PATH, true);
$class = $loader->load(function (Compiler $compiler): void {
$compiler->addExtension('dbal', new DbalExtension());
$compiler->addExtension('orm', new OrmExtension());
$compiler->addExtension('orm.annotations', new OrmAnnotationsExtension());
$compiler->addConfig([
'parameters' => [
'tempDir' => TEMP_PATH,
'appDir' => __DIR__,
],
]);
}, self::class . __METHOD__);
/** @var Container $container */
$container = new $class();
$registry = $container->getByType(ManagerRegistry::class);
$this->assertInstanceOf(ManagerRegistry::class, $registry);
$registry->getManager()->close();
$this->assertFalse($registry->getManager()->isOpen());
$registry->resetManager();
$this->assertTrue($registry->getManager()->isOpen());
}
}

0 comments on commit 6b5384e

Please sign in to comment.
You can’t perform that action at this time.