Travis CI is great and we’re using a very (VERY) simple singular test that just checks whether or not Titan Framework encounters any activation errors. As of the moment we haven’t wrote any other detailed tests for Titan, and that simple activation test soon will no longer cut it.

Ideally, testing would be done both remotely and locally during development so that you can catch errors quickly.. probably with a Gulp watch running the tests, but that would be for another article. I did some research on running PHPUnit tests locally and found Pippin’s 4-part blog post on Unit Testing for WordPress Plugins really helpful (read it if you haven’t yet). We’re using that as our guide to adding unit tests for Titan.

As of the moment we’re using VVV as our development environment, and it’s good that it already has WP-CLI and PHPUnit pre-installed so we can quickly jump into trying out unit testing locally. Titan already has a bin/ so we don’t need to do a wp scaffold. We tried initializing the testing environment using this command inside VVV:

$ bash bin/ wordpress_unit_tests root 'root' localhost latest

Surprise, the command failed. It works when Travis CI uses it, but it fails inside VVV. Why? Because Travis CI runs it’s tests on an empty environment, while VVV already has a bunch of development stuff inside it like a development copy of WordPress.

Not only that, the normal installer script would take a long time to finish since it downloads the WordPress installer, unzips it and uses that one as the testing environment. IF we performed testing across all our plugins, that would take up precious time.

So we modified the to only download stuff only when necessary and so skip cloning of the dev copy of WordPress if it already exists. Now, the script works locally inside VVV and it still works great also in Travis CI.

Here’s the copy of the install script that Titan Framework uses if anyone finds it useful:

For newly scaffolded projects, here’s the modified one:

Leave a Reply

Your email address will not be published. Required fields are marked *