in Uncategorized

Setup Wercker CI with WordPress Plugins

If you’re writing a plugin that really needs to be bug free, functional or unit tests are highly recommended. Wercker is a Continues Integration platform that seamlessly works with WordPress. Lately, I have been working on a WordPress plugin that sends and receives data with accounting systems. For such an critical system functional and unit tests are really important.

This article will tell you exactly how to integrate Wercker with your WordPress plugin. There are plenty of Continues Integration providers. I chose Wercker because they support private repositories, is free* and works seamlessly with Bitbucket. I will go through the whole process from scratch.

A prerequiste is that you have a wordpress installation with your custom plugin installed. Also this plugin should be version controlled using git.

Lets first install some essentials.

Install phpunit

PHPUnit is the testing framework. Let’s install that on your local machine if it’s not already installed.

Install wp-cli

Wp CLI is an awesome tool for WordPress. We will use it to generate boilerplate files inside our plugin folder.

Scaffold phpunit configuration

Lets now use WP-CLI to generate test files and configuration.

Some new files will then be created in your plugin folder (phpunit.xml.dist, tests etc).

 

Test phpunit

Lets see if everything works.

Write your own tests

Tests should be located inside the “tests” folder. By default phpunit is configured to add files that start with “test-” as a test class. By default the scaffold should have created a simple test for you.

Wercker

Here is a working wercker.yml script that works with the awesome Continues integration service Wercker. Put the wercker.yml file in the root of your plugin. The gotcha here is that we re-enable mysql, since mysql_X functions are disabled by default.

 

Share this post

Facebooktwittergoogle_plusredditpinterestlinkedinmail

Write a Comment

Comment