Codeception — automated database dumps

Why Codeception?

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:

  • unit
  • functional
  • api

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.

Did you like this post?
Previous post

Laravel Clyde — image uploads, resizing & manipulations for Laravel

It's very common for web applications to deal with image uploads, image resizing and other manipulations. Arguably the best approach to the problem (apart from offloading the task to a service like imgix) is to store the uploads in the cloud and resize and manipulate the images on the fly.
Next post

Handling Braintree webhooks in Laravel Cashier

Laravel Cashier is already handling Braintree's 'subscription_canceled' and 'subscription_expired' webhooks and will cancel a subscription when any of those webhooks get triggered. The webhooks are handled by WebhookController, which can be easily extended to add support for other kinds of webhooks.