[FEATURE] Add CSV dataset export for functional tests#698
[FEATURE] Add CSV dataset export for functional tests#698bmack wants to merge 1 commit intoTYPO3:mainfrom
Conversation
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')) { |
There was a problem hiding this comment.
Not sure about that ... at least we should use a naming reflecting the case DATASETS are not always exported:
| 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; |
There was a problem hiding this comment.
| $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; |
There was a problem hiding this comment.
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) . '"'; |
There was a problem hiding this comment.
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
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:
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.