Codeception — automated database dumps
April 16, 2016
I’ve been recently using Codeception and really appreciate what it can do. I see Codeception as a natural next step from PHPUnit. What's nice about Codeception is that existing classic PHPUnit tests are compatible with it, so not all work is lost for people moving from PHPUnit to Codeception. When I was working on Wittly I ended up by creating 3 different test suites holding different types of tests:
Each of the test suites can be run on its own or all of them can be run in one go.
Dumping a database for Codeception can be inconvenient
There’s a slight inconvenience related to functional and acceptance testing in Codeception though.
As you may know functional and acceptance tests usually run against a test database. Codeception comes with a nice Db module that keeps the test database clean before each test is run. To use it you are expected to put a database dump in 'tests/_data' directory. This is a major pain, because each time the database schema changes, a new dump is required.
Since I plan to use Codeception more in the future I made a package that adds a single command to a project that will migrate, seed and dump a test database making it ready to be used in Codeception tests.
It’s a timesaver and finally I don’t have to remember about creating a database dump manually.