lundi 12 juin 2017

Codeception acceptance tests within database transaction on MySQL

Writing acceptance tests using Codeception for our Custom (with Symfony components and Doctrine) framework. We have a set of utility methods, used separately by our Phpunit tests, for creating various entities to test against. This includes things such as users, and other related data.

In the case of our Codeception tests we want to make use of this functionality, allowing us to seed custom data and clean it up afterwards. In the context of our Unit tests this is handled by a transaction. Given that Codeception makes requests to our application through Phantomjs over HTTP it can't make use of transactions as a separate database connection is created to the one used by the tests (It looks like this would be possible using Dbh but as far as I can see this isn't supported by MySQL as there's no support for nested transactions). The result of this is that the acceptance test can seed data, but this data doesn't exist within the external request unless the data is persisted.

The only other solution I can think is to trigger a database dump before the test suite runs. Persist our testing data to the database so it's accessible to the external requests, and then restore the dumped database when the test suite has completed. We have a pretty big database though and this is going to add substantial overhead to running the test suite.

I'm hoping there's other options available, or something else we can try. Thanks.

Aucun commentaire:

Enregistrer un commentaire