diff --git a/module/Common/src/Doctrine/ReopeningEntityManager.php b/module/Common/src/Doctrine/ReopeningEntityManager.php index 134dcd22..e040b978 100644 --- a/module/Common/src/Doctrine/ReopeningEntityManager.php +++ b/module/Common/src/Doctrine/ReopeningEntityManager.php @@ -5,13 +5,14 @@ namespace Shlinkio\Shlink\Common\Doctrine; use Doctrine\ORM\Decorator\EntityManagerDecorator; use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; class ReopeningEntityManager extends EntityManagerDecorator { - protected function getWrappedEntityManager(): EntityManager + protected function getWrappedEntityManager(): EntityManagerInterface { if (! $this->wrapped->isOpen()) { - $this->wrapped= EntityManager::create( + $this->wrapped = EntityManager::create( $this->wrapped->getConnection(), $this->wrapped->getConfiguration(), $this->wrapped->getEventManager() diff --git a/module/Common/src/Doctrine/ReopeningEntityManagerDelegator.php b/module/Common/src/Doctrine/ReopeningEntityManagerDelegator.php index 2de8b651..3128b0cf 100644 --- a/module/Common/src/Doctrine/ReopeningEntityManagerDelegator.php +++ b/module/Common/src/Doctrine/ReopeningEntityManagerDelegator.php @@ -3,15 +3,12 @@ declare(strict_types=1); namespace Shlinkio\Shlink\Common\Doctrine; -use Doctrine\ORM\EntityManagerInterface; use Psr\Container\ContainerInterface; class ReopeningEntityManagerDelegator { public function __invoke(ContainerInterface $container, string $name, callable $callback): ReopeningEntityManager { - /** @var EntityManagerInterface $em */ - $em = $callback(); - return new ReopeningEntityManager($em); + return new ReopeningEntityManager($callback()); } } diff --git a/module/Common/test/Doctrine/ReopeningEntityManagerDelegatorTest.php b/module/Common/test/Doctrine/ReopeningEntityManagerDelegatorTest.php new file mode 100644 index 00000000..1193541b --- /dev/null +++ b/module/Common/test/Doctrine/ReopeningEntityManagerDelegatorTest.php @@ -0,0 +1,28 @@ +prophesize(EntityManagerInterface::class)->reveal(); + $result = (new ReopeningEntityManagerDelegator())(new ServiceManager(), '', function () use ($em) { + return $em; + }); + + $ref = new ReflectionObject($result); + $prop = $ref->getProperty('wrapped'); + $prop->setAccessible(true); + + $this->assertSame($em, $prop->getValue($result)); + } +}