Skip to content

Commit

Permalink
make it work with DBAL 4
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaicher committed Oct 22, 2023
1 parent 093ecbd commit c3b0db0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
13 changes: 10 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"require": {
"php": "^7.3 || ^8.0",
"ext-json": "*",
"doctrine/dbal": "4.0.x-dev as 3.999",
"doctrine/doctrine-bundle": "^2.2.2",
"doctrine/dbal": "^3.3 || ^4.0",
"doctrine/doctrine-bundle": "dev-dbal_4",
"psr/cache": "^1.0 || ^2.0 || ^3.0",
"symfony/cache": "^5.4 || ^6.2 || ^7.0",
"symfony/framework-bundle": "^5.4 || ^6.2 || ^7.0"
Expand Down Expand Up @@ -53,5 +53,12 @@
},
"config": {
"sort-packages": true
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/dmaicher/DoctrineBundle"
}
],
"minimum-stability": "dev"
}
30 changes: 27 additions & 3 deletions src/DAMA/DoctrineTestBundle/Doctrine/DBAL/StaticDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Doctrine\DBAL\Connection\StaticServerVersionProvider;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\Connection;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class StaticDriver extends Driver\Middleware\AbstractDriverMiddleware
{
Expand Down Expand Up @@ -36,9 +37,7 @@ public function connect(array $params): Connection

$connection = self::$connections[$key];

$platform = $params['platform'] ?? (isset($params['serverVersion'])
? $this->createDatabasePlatformForVersion($params['serverVersion'])
: $this->getDatabasePlatform());
$platform = $this->getPlatform($connection, $params);

if (!$platform->supportsSavepoints()) {
throw new \RuntimeException('This bundle only works for database platforms that support savepoints.');
Expand Down Expand Up @@ -77,4 +76,29 @@ public static function commit(): void
$connection->commit();
}
}

private function getPlatform(Connection $connection, array $params): AbstractPlatform
{
if (isset($params['platform'])) {
return $params['platform'];
}

// DBAL 3
if (method_exists($this, 'createDatabasePlatformForVersion')) {
if (isset($params['serverVersion'])) {
return $this->createDatabasePlatformForVersion($params['serverVersion']);
}

return $this->getDatabasePlatform();
}

// DBAL 4
if (isset($params['serverVersion'])) {
$versionProvider = new StaticServerVersionProvider($params['serverVersion']);
} else {
$versionProvider = new StaticServerVersionProvider($connection->getServerVersion());
}

return $this->getDatabasePlatform($versionProvider);
}
}
2 changes: 1 addition & 1 deletion tests/Functional/FunctionalTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function rollbackSavepoint(string $name): void

private function init(): void
{
$this->kernel = new AppKernel('test', false);
$this->kernel = new AppKernel('test', true);
$this->kernel->boot();
$this->connection = $this->kernel->getContainer()->get('doctrine.dbal.default_connection');
}
Expand Down

0 comments on commit c3b0db0

Please sign in to comment.