Migrate XML to CSV datasets for TYPO3 Testing Framework
In previous versions of TYPO3 testing framework, it was possible to
import XML datasets into the database before executing functional tests. For some reason, the method importDataSet()
was marked as deprecated and finally removed long time ago.
The new official way to handle datasets is the CSV file format and the method importCSVDataSet().
However, I am currently working on a TYPO3 project with several functional tests and multiple dozens of XML dataset files. And because good programmers are lazy, I wondered if there is a fast way to migrate all the existing XML dataset files into CSV dataset files. After a short search and no results, I asked my TYPO3 bubble in the fediverse, but it seemed, there is no existing solution.
So I decided to write a script by myself. It took me about 1 to 2 hours until I was happy. Maybe it is not perfect, but it worked for my needs. I published it as composer package: koehnlein/dataset-migrator
Installations #
It can be installed in your composer based TYPO3 installation:
composer req koehnlein/dataset-migrator --dev
Usage #
The script can process one directory at once. The directory path is passed as argument:
vendor/bin/typo3 datasets:xmltocsv <directory>
Concrete Example #
vendor/bin/typo3 datasets:xmltocsv packages/my_extension/Tests/Functional/Fixtures
Multiple Directories #
One example to process multiple directories could be the find command, depending on your folder structure. If you
have your dataset files placed in folders named "Fixtures", your command could look like this:
find packages -name 'Fixtures' -type d -exec vendor/bin/typo3 datasets:xmltocsv {} \;