Skip to content

Commit

Permalink
[TASK] Avoid invalid database name configuration
Browse files Browse the repository at this point in the history
Database name only allows a special set of characters.
Based on the configured database name, functional test
creates databases per functional test case.

Due to the general policy the typo3/testing-framework
should not silently fix setup errors. Therefore, invalid
database name configuration is now detected, throwing a
`\RuntimeException` with a use-full exception message.

Releases: main, 7
  • Loading branch information
BenjaminBeck authored and sbuerk committed Oct 11, 2023
1 parent e353cbc commit c833927
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s lint

- name: Phpstan
if: ${{ matrix.php <= '8.1' }}
if: ${{ matrix.php <= '8.0' }}
run: Build/Scripts/runTests.sh -p ${{ matrix.php }} -s phpstan

- name: Unit Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ private function setInDataMap(
// current item did not have any values in data map, use last identifer
if ($currentIndex === false && !empty($identifiers)) {
$values['pid'] = '-' . $identifiers[count($identifiers) - 1];
// current item does have values in data map, use previous identifier
// current item does have values in data map, use previous identifier
} elseif ($currentIndex > 0) {
$previousIndex = $identifiers[$currentIndex - 1];
$values['pid'] = '-' . $identifiers[$previousIndex];
Expand Down
10 changes: 10 additions & 0 deletions Classes/Core/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,16 @@ protected function setUp(): void
$dbDriver = $localConfiguration['DB']['Connections']['Default']['driver'];
if ($dbDriver !== 'pdo_sqlite') {
$originalDatabaseName = $localConfiguration['DB']['Connections']['Default']['dbname'];
if ($originalDatabaseName !== preg_replace('/[^a-zA-Z0-9_]/', '', $originalDatabaseName)) {
throw new \RuntimeException(
sprintf(
'Database name "%s" is invalid. Use a valid name, for example "%s".',
$originalDatabaseName,
preg_replace('/[^a-zA-Z0-9_]/', '', $originalDatabaseName)
),
1695139917
);
}
// Append the unique identifier to the base database name to end up with a single database per test case
$dbName = $originalDatabaseName . '_ft' . $this->identifier;
$localConfiguration['DB']['Connections']['Default']['dbname'] = $dbName;
Expand Down

0 comments on commit c833927

Please sign in to comment.