Skip to content

Commit 76acb9c

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 c1330b8 commit 76acb9c

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Classes/Core/Testbase.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,14 @@ public function setUpPackageStates(
626626
public function setUpTestDatabase(string $databaseName, string $originalDatabaseName): void
627627
{
628628
// First close existing connections from a possible previous test case and
629-
// tell our ConnectionPool there are no current connections anymore.
629+
// tell our ConnectionPool there are no current connections anymore. In case
630+
// database does not exist yet, an exception is thrown which we catch here.
630631
$connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
631-
$connection = $connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
632-
$connection->close();
632+
try {
633+
$connection = $connectionPool->getConnectionByName(ConnectionPool::DEFAULT_CONNECTION_NAME);
634+
$connection->close();
635+
} catch (DBALException $_) {
636+
}
633637
$connectionPool->resetConnections();
634638

635639
// Drop database if exists. Directly using the Doctrine DriverManager to

0 commit comments

Comments
 (0)