Skip to content

Commit e98bd22

Browse files
committed
[doctrine/dbal] Enabled FK middleware for SQLite
1 parent b490618 commit e98bd22

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tests/lib/Persistence/DatabaseConnectionFactory.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@
99
namespace Ibexa\Tests\Core\Persistence;
1010

1111
use Doctrine\Common\EventManager;
12+
use Doctrine\DBAL\Configuration;
1213
use Doctrine\DBAL\Connection;
14+
use Doctrine\DBAL\Driver\AbstractSQLiteDriver\Middleware\EnableForeignKeys;
1315
use Doctrine\DBAL\DriverManager;
16+
use Doctrine\DBAL\Platforms\SqlitePlatform;
1417

1518
/**
1619
* Database connection factory for integration tests.
@@ -70,15 +73,19 @@ public function createConnection(string $databaseURL): Connection
7073
// set DbPlatform based on database url scheme
7174
$scheme = parse_url($databaseURL, PHP_URL_SCHEME);
7275
$driverName = 'pdo_' . $scheme;
76+
$config = new Configuration();
7377
if (isset($this->databasePlatforms[$driverName])) {
7478
$params['platform'] = $this->databasePlatforms[$driverName];
7579
// add predefined event subscribers only for the relevant connection
7680
$params['platform']->addEventSubscribers($this->eventManager);
81+
if ($params['platform'] instanceof SqlitePlatform) {
82+
$config->setMiddlewares([new EnableForeignKeys()]);
83+
}
7784
}
7885

7986
self::$connectionPool[$databaseURL] = DriverManager::getConnection(
8087
$params,
81-
null,
88+
$config,
8289
$this->eventManager
8390
);
8491
self::$connectionPool[$databaseURL]->setNestTransactionsWithSavepoints(true);

0 commit comments

Comments
 (0)