Skip to content

Commit 89313ea

Browse files
committed
[TASK] Mitigiate deprecated database configuration
This change writes functioal test instance database configuration using doctrine/dbal identifiers and structure directly. Thus, avoiding the need for the TYPO3 ConnectionPool to transform these values on the fly. Instead of default connection array $GLOBALS['TYPO3_CONF_VARS_']['DB']['Connections'] ['Default']['tableoptions'] = [] following array is written $GLOBALS['TYPO3_CONF_VARS']['DB']['Connections'] ['Default']['defaultTableOptions'] = [] for database driver `mysqli` and `pdo_mysql`, other platforms does not suport these settings. Additionally, `COLLATION` is used instead of the replaced `COLLATE` subkey to define the table collation within the default table options. Backport to typo3/testing-framework v8 will limit this to TYPO3 v13 and for v12 using the old values. [1] doctrine/dbal#5246 [2] https://review.typo3.org/c/Packages/TYPO3.CMS/+/75211/4/typo3/sysext/core/Classes/Database/ConnectionPool.php#147 Releases: main, 8
1 parent 480edc8 commit 89313ea

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

Classes/Core/Functional/FunctionalTestCase.php

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ protected function setUp(): void
310310
$testbase->linkFrameworkExtensionsToInstance($this->instancePath, $frameworkExtension);
311311
$testbase->linkPathsInTestInstance($this->instancePath, $this->pathsToLinkInTestInstance);
312312
$testbase->providePathsInTestInstance($this->instancePath, $this->pathsToProvideInTestInstance);
313+
$localConfiguration = [];
313314
$localConfiguration['DB'] = $testbase->getOriginalDatabaseSettingsFromEnvironmentOrLocalConfiguration();
314315

315316
$originalDatabaseName = '';
@@ -332,15 +333,49 @@ protected function setUp(): void
332333
$localConfiguration['DB']['Connections']['Default']['dbname'] = $dbName;
333334
$testbase->testDatabaseNameIsNotTooLong($originalDatabaseName, $localConfiguration);
334335
if ($dbDriver === 'mysqli' || $dbDriver === 'pdo_mysql') {
335-
$localConfiguration['DB']['Connections']['Default']['charset'] = 'utf8mb4';
336-
$localConfiguration['DB']['Connections']['Default']['tableoptions']['charset'] = 'utf8mb4';
337-
$localConfiguration['DB']['Connections']['Default']['tableoptions']['collate'] = 'utf8mb4_unicode_ci';
338-
$localConfiguration['DB']['Connections']['Default']['initCommands'] = 'SET SESSION sql_mode = \'STRICT_ALL_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY\';';
336+
if ((new Typo3Version())->getMajorVersion() < 13) {
337+
// This branch is removed in testing-framework ^9
338+
$localConfiguration['DB']['Connections']['Default']['charset'] = 'utf8mb4';
339+
$localConfiguration['DB']['Connections']['Default']['tableoptions']['charset'] = 'utf8mb4';
340+
$localConfiguration['DB']['Connections']['Default']['tableoptions']['collate'] = 'utf8mb4_unicode_ci';
341+
} else {
342+
// MySQL/MariaDB allows more specific settings, and default configuration specific to these
343+
// platforms are handled here. That includes using the more specific `utf8mb4` charset like
344+
// TYPO3 would determine and write during installation and also defining `defaultTableOptions`
345+
// based on selected charset.
346+
if (($localConfiguration['DB']['Connections']['Default']['charset'] ?? '') === '') {
347+
$localConfiguration['DB']['Connections']['Default']['charset'] = 'utf8mb4';
348+
}
349+
if (($localConfiguration['DB']['Connections']['Default']['defaultTableOptions']['charset'] ?? '') === '') {
350+
$localConfiguration['DB']['Connections']['Default']['defaultTableOptions']['charset'] = 'utf8mb4';
351+
}
352+
if (($localConfiguration['DB']['Connections']['Default']['defaultTableOptions']['collation'] ?? '') === '') {
353+
$localConfiguration['DB']['Connections']['Default']['defaultTableOptions']['collation']
354+
= $localConfiguration['DB']['Connections']['Default']['defaultTableOptions']['charset'] . '_unicode_ci';
355+
}
356+
}
357+
$localConfiguration['DB']['Connections']['Default']['initCommands']
358+
= 'SET SESSION sql_mode = \'' . implode(',', [
359+
'STRICT_ALL_TABLES',
360+
'ERROR_FOR_DIVISION_BY_ZERO',
361+
'NO_AUTO_VALUE_ON_ZERO',
362+
'NO_ENGINE_SUBSTITUTION',
363+
'NO_ZERO_DATE',
364+
'NO_ZERO_IN_DATE',
365+
'ONLY_FULL_GROUP_BY',
366+
]) . '\';';
367+
}
368+
// Postgres/SQLite requires to use `utf-8` as charset and does not support `utf8mb4`.
369+
if (($localConfiguration['DB']['Connections']['Default']['charset'] ?? '') === '') {
370+
$localConfiguration['DB']['Connections']['Default']['charset'] = 'utf-8';
339371
}
340372
} else {
341373
// sqlite dbs of all tests are stored in a dir parallel to instance roots. Allows defining this path as tmpfs.
342374
$testbase->createDirectory(dirname($this->instancePath) . '/functional-sqlite-dbs');
343375
$localConfiguration['DB']['Connections']['Default']['path'] = $dbPathSqlite;
376+
if (($localConfiguration['DB']['charset'] ?? '') === '') {
377+
$localConfiguration['DB']['charset'] = 'utf-8';
378+
}
344379
}
345380

346381
// Set some hard coded base settings for the instance. Those could be overruled by

0 commit comments

Comments
 (0)