diff --git a/manager-bundle/src/ContaoManager/Plugin.php b/manager-bundle/src/ContaoManager/Plugin.php index 20395862f9e..0006dc8484c 100644 --- a/manager-bundle/src/ContaoManager/Plugin.php +++ b/manager-bundle/src/ContaoManager/Plugin.php @@ -68,6 +68,11 @@ class Plugin implements BundlePluginInterface, ConfigPluginInterface, RoutingPlu */ private $dbalConnectionFactory; + public function __construct(callable $dbalConnectionFactory = null) + { + $this->dbalConnectionFactory = $dbalConnectionFactory ?: [DriverManager::class, 'getConnection']; + } + /** * Sets the path to enable autoloading of legacy Contao modules. */ @@ -76,11 +81,6 @@ public static function autoloadModules(string $modulePath): void static::$autoloadModules = $modulePath; } - public function __construct(callable $dbalConnectionFactory = null) - { - $this->dbalConnectionFactory = $dbalConnectionFactory ?: [DriverManager::class, 'getConnection']; - } - /** * {@inheritdoc} */ @@ -316,9 +316,6 @@ private function handlePrependLocale(array $extensionConfigs, ContainerBuilder $ /** * Adds the database server version to the Doctrine DBAL configuration. * - * If there are no DB credentials yet (install tool), we have to set the - * server version to prevent a DBAL exception (see #1422). - * * @return array>>> */ private function addDefaultServerVersion(array $extensionConfigs, ContainerBuilder $container): array @@ -344,7 +341,7 @@ private function addDefaultServerVersion(array $extensionConfigs, ContainerBuild // If there are no DB credentials yet (install tool), we have to set // the server version to prevent a DBAL exception (see #1422) try { - $connection = call_user_func($this->dbalConnectionFactory, $params); + $connection = \call_user_func($this->dbalConnectionFactory, $params); $connection->connect(); $connection->close(); } catch (DriverException $e) { diff --git a/manager-bundle/tests/ContaoManager/PluginTest.php b/manager-bundle/tests/ContaoManager/PluginTest.php index 38345a81584..befe0ba40ee 100644 --- a/manager-bundle/tests/ContaoManager/PluginTest.php +++ b/manager-bundle/tests/ContaoManager/PluginTest.php @@ -400,8 +400,15 @@ public function testRetrievesTheConnectionParametersFromTheConfiguration(): void ]; $connection = $this->createMock(Connection::class); - $connection->expects($this->once())->method('connect'); - $connection->expects($this->once())->method('close'); + $connection + ->expects($this->once()) + ->method('connect') + ; + + $connection + ->expects($this->once()) + ->method('close') + ; $dbalConnectionFactory = function ($params) use ($connection) { $this->assertSame( @@ -411,6 +418,7 @@ public function testRetrievesTheConnectionParametersFromTheConfiguration(): void ], $params ); + return $connection; };