Skip to content

Commit d317133

Browse files
committed
[TASK] Streamline Testbase->setUpTestDatabase()
The `Testbase->setUpTestDatabase()` takes care of correct database setup for each test instance and that the database is created. To accomplish that, current TYPO3 connections are closed. Doctrine DriverManager is used as lowlevel tool to create the instance database. In case that the database has not been created, which occures on the first test execution per test-case, an exception is thrown and disturbes the `getDatabasePlatform <-> getServerVersion()` detection with the Doctrine construct. That has been mitigated by catching the exception within `Connection->getServerVersion()` and returning an empty string ending up retrieving at least a the lowest default platform for the driver. That was mainly a workaround in functional test runs. Doctrine DBAL 3.9.x & 4.1.x will introduce a new version based postgres platform class along with a new exception, if the server version does not match the version pattern - which is the case for an emtpy string and not returning a PostgresSQL platform anymore - failing to create the database. This change catches the exception for non existing database to prepare the removal of the connection workaround in `Connection->getServerVersion()`, but still ensures the ConnectionPool instances are closed. Minor code cleanups within the method are applied in the same run.
1 parent 3c758b0 commit d317133

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Classes/Core/Testbase.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,10 +668,14 @@ public function setUpPackageStates(
668668
public function setUpTestDatabase(string $databaseName, string $originalDatabaseName): void
669669
{
670670
// First close existing connections from a possible previous test case and
671-
// tell our ConnectionPool there are no current connections anymore.
671+
// tell our ConnectionPool there are no current connections anymore. In case
672+
// database does not exist yet, an exception is thrown which we catch here.
672673
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
673-
$connection = $connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
674-
$connection->close();
674+
try {
675+
$connection = $connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
676+
$connection->close();
677+
} catch (DBALException) {
678+
}
675679
$connectionPool->resetConnections();
676680

677681
// Drop database if exists. Directly using the Doctrine DriverManager to
@@ -689,8 +693,8 @@ public function setUpTestDatabase(string $databaseName, string $originalDatabase
689693
$configuration->setSchemaManagerFactory($coreSchemaFactory);
690694
}
691695
$driverConnection = DriverManager::getConnection($connectionParameters, $configuration);
696+
692697
$schemaManager = $driverConnection->createSchemaManager();
693-
$platform = $driverConnection->getDatabasePlatform();
694698
$isSQLite = self::isSQLite($driverConnection);
695699

696700
// doctrine/dbal no longer supports createDatabase() and dropDatabase() statements. Guard it.

0 commit comments

Comments
 (0)