Nimut / testing-framework

TYPO3 testing framework that provides base classes and configuration for PHPUnit tests
GNU General Public License v2.0
52 stars 25 forks source link

Update/Rework database testing #74

Closed jdoubleu closed 6 years ago

jdoubleu commented 6 years ago

Are there any plans on updating the Data Set/Fixture loading functions?

As for now the importDataSet() function of the FunctionalTestCase ist only able to load XML files. I'd like to use php files as well.

The PHPUnit framework already supports PHP, Csv and Yaml sources (see https://phpunit.de/manual/current/en/database.html, sections Array DataSet, CSV DataSet and YAML DataSet). As I can see, you aren't using the database testing abilities from PHPUnit either. Maybe this part of this framework can be updated too.

I'd like to contribute to this project. At first I thought about extending the importDataSet() to support PHP files, but this seems obsolete now. I'd rather update the whole database testing part and make it compatible with PHPUnit.

Can I open a PR (it might take a while) and submit changes? Of course there must be concept first.

I'd really like to see these changes in this TYPO3 testing framework.

IchHabRecht commented 6 years ago

Hi @jdoubleu,

Thank you for your information. We don't have any plans to change the way how fixtures work inside the testing-framework. Basically we don't want to diverse from https://github.com/TYPO3/testing-framework too much.

As you would like to use some PHP files as Fixture files, I would suggest to return some kind of array from within those files like

return [
    'pages' => [
        [
            'uid' => 1,
            'pid' => 0,
            'title' => 'Root',
            'deleted' => 0,
            'perms_everybody' => 15,
        ],
    ],
];

In your test setup you can then simply iterate over that array and use the database to insert your provided fixtures:

$databaseFixtures = require('Fixtures.php');
foreach ($databaseFixtures as $table => $inserts) {
    foreach ($inserts as $insertArray) {
        $this->getDatabaseConnection()->insertArray($table, $insertArray);
    }
}

I hope this already helps you to solve your problem.

jdoubleu commented 6 years ago

As you would like to use some PHP files as Fixture files, I would suggest to return some kind of array from within those files

I'd have created used the PHP-Files, or Array DataSet, that way. You're right, that I could include them by myself in the tests. For now I'm trying to use this. Thanks for your advice.

Although using the, importDataSet() function would be nice because it also resolves the include paths, etc and seems to be the correct way for me.

Would you accept a pull request? I'd only extend the importDataSet() by a few more loaders while staying backwards-compatible.

IchHabRecht commented 6 years ago

Hi @jdoubleu,

As I tried to explain, we don't want to divided to the typo3 testing-framework to much. That's why I would kindly ask you to first get in contact there and ask if it would be possible to extend the importDataSet(). If this framework extends its functionality, you are more than welcome to even push it in here.

Thanks for your understanding!