Skip to content

[FEATURE] Add CSV dataset export for functional tests#698

Open
bmack wants to merge 1 commit intoTYPO3:mainfrom
bmack:feature/csvs
Open

[FEATURE] Add CSV dataset export for functional tests#698
bmack wants to merge 1 commit intoTYPO3:mainfrom
bmack:feature/csvs

Conversation

@bmack
Copy link
Member

@bmack bmack commented Feb 5, 2026

Introduce exportCSVDataSet() to write current database state to CSV files matching the existing fixture format. This completes the import → assert → export workflow for functional tests.

Usage example:

$this->exportCSVDataSet(
    $this->instancePath . '/export.csv',
    ['pages' => ['uid', 'pid', 'title'], 'tt_content']
);

Tables can specify explicit fields or export all columns.

Additionally, assertCSVDataSet() now auto-exports the actual database state to a _actual.csv file when assertions fail and the TYPO3_TESTING_EXPORT_DATASETS environment variable is set.

Introduce exportCSVDataSet() to write current database state
to CSV files matching the existing fixture format. This completes
the import → assert → export workflow for functional tests.

Usage example:

    $this->exportCSVDataSet(
        $this->instancePath . '/export.csv',
        ['pages' => ['uid', 'pid', 'title'], 'tt_content']
    );

Tables can specify explicit fields or export all columns.

Additionally, assertCSVDataSet() now auto-exports the actual
database state to a _actual.csv file when assertions fail and
the TYPO3_TESTING_EXPORT_DATASETS environment variable is set.
}

if (!empty($failMessages)) {
if (getenv('TYPO3_TESTING_EXPORT_DATASETS')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about that ... at least we should use a naming reflecting the case DATASETS are not always exported:

Suggested change
if (getenv('TYPO3_TESTING_EXPORT_DATASETS')) {
if ((bool)getenv('TYPO3_TESTING_EXPORT_DATASETS_ON_FAILED_ASSERTION')) {

$firstTable = false;

// Table name line with trailing commas
$output .= '"' . $tableName . '"' . str_repeat(',', count($fields)) . LF;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$output .= '"' . $tableName . '"' . str_repeat(',', count($fields)) . LF;
$output .= '"' . $tableName . '",' . LF;

We lifted the requirement to have matching , table name lines, so the str_repeat() is not needed (anymore) - at least if I remember that correctly.

if ($value === null) {
return '\\NULL';
}
$stringValue = (string)$value;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about the implementation here, all values are converted to strings and some generic formating.

Not sure if we should bind that to the real database schema inforamation for table/column ... , having text/string/varchar field values always enquoted and other data (int, float/double, ) in the respected form.

Also thinking about native json fields for supported dbms (not using fallback TEXT/CBOLB for the others etc ) ....

Needs some thinking about this ...

return '""';
}
if (preg_match('/[,"\n\r\\\\]/', $stringValue)) {
return '"' . str_replace('"', '""', $stringValue) . '"';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only quotes text values if they contain , " or some line breaks. If not, they are not quoted ...

GIVEN...: Some Text
EXPECTED: "Some Text"
ACTUAL..: Some Text

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants