Register 'dbal' service in UpdatePatcher (#3616)

* Register 'dbal' service in UpdatePatcher

* Fix for pull request finding

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Adam DaleyandCopilot Autofix powered by AI authored and GitHub committed 2026-05-27 04:17:24 +01:00
1 parent 277ce9b50e
commit f101226bf5
2 files changed
+40

No files matched your search

@@ -11,7 +11,9 @@ declare(strict_types=1);
namespace FOSSBilling;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;
use FOSSBilling\Doctrine\DriverManagerFactory;
use Symfony\Component\Filesystem\Exception\IOException;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Filesystem\Path;
@@ -30,6 +32,10 @@ class UpdatePatcher implements InjectionAwareInterface
public function setDi(\Pimple\Container $di): void
{
if (!$di->offsetExists('dbal')) {
$di['dbal'] = static fn (): Connection => DriverManagerFactory::getConnection();
}
$this->di = $di;
}
@@ -0,0 +1,34 @@
<?php
declare(strict_types=1);
use FOSSBilling\UpdatePatcher;
use PHPUnit\Framework\Attributes\Group;
#[Group('Core')]
final class UpdatePatcherTest extends PHPUnit\Framework\TestCase
{
public function testSetDiRegistersDbalWhenUpdatingWithLegacyContainer(): void
{
$di = new Pimple\Container();
self::assertFalse($di->offsetExists('dbal'));
$patcher = new UpdatePatcher();
$patcher->setDi($di);
self::assertTrue($di->offsetExists('dbal'));
}
public function testSetDiDoesNotOverrideExistingDbalEntry(): void
{
$di = new Pimple\Container();
$sentinel = new stdClass();
$di['dbal'] = $sentinel;
$patcher = new UpdatePatcher();
$patcher->setDi($di);
self::assertSame($sentinel, $di['dbal']);
}
}