Travis CI WordPress Configuration and Setup

Kevin Dees cad7791120 Update 2 years ago
bin 0d82693afb Update 2 years ago
tests 50d4464642 disable email 2 years ago
.gitattributes 4e03b59289 Create .gitattributes 2 years ago
.travis.yml d5ba9099c4 Update .travis.yml 2 years ago
LICENSE 6eefda6bb1 Initial commit 2 years ago cad7791120 Update 2 years ago
composer.json 0e9cc8a346 Create composer.json 2 years ago

Travis CI and WordPress Integration for Composer Packages

Travis CI WordPress configuration and setup for PHP 5.6 and 5.5 for composer and PHP Unit tests. Read more about Continuous Integration from Martin Fowler.

  • With this setup, WordPress is fully loaded before tests are run.
  • Disable wp_mail to prevent tests from failing
  • Any WordPress hooks will not be implemented - like add_action and add_filter. You can configure it to be otherwise but for my needs, I have not (no instructions for this).
  • This configuration is only setup for composer package projects (using composer). Edit the composer.json to your specification and needs.

Composer's default is PHP Unit 4.8 because I need compatibility with PHP 5.5.9. If you do not have these requirements update the composer.json file accordingly.

Travis CI Tests

Use this project as your base configuration and you are ready to go. Otherwise, copy the files and settings you need.

When you push to GitHub with Travis CI integrated your Tests in the tests folder will be run as expected.

Here is the Travis CI documentation you will care most about:

Local Tests

When doing local tests I use Laravel Homestead vagrant box add laravel/homestead. Then from the project directory like ~/Code/project I run a few command on the VM to download and install WordPress. Finally I use PHPStorm to run tests with coverage.

PHP Storm Example


Create the wordpress database on the guest machine Homestead:

mysql -e "SET NAMES utf8; create database IF NOT EXISTS wordpress;" -uroot

Download WordPress

Download and install WordPress with wp-cli.phar:

curl -O
chmod +x wp-cli.phar
./wp-cli.phar core download --allow-root --path=wordpress
./wp-cli.phar core config --allow-root --dbname=wordpress --dbuser=homestead --dbpass=secret --dbhost= --path=wordpress
./wp-cli.phar core install --allow-root --admin_name=admin --admin_password=admin [email protected] --url=http://tests.wp --title=WordPress --path=wordpress

Configure Homestead

In the Homestead.yaml file I add the wordpress site:

  - map: tests.wp
    to: /home/vagrant/Code/project/wordpress

Update hosts file

In the host computers hosts file I point tests.wp to the Homestead IP. In my Homestead.yaml file it is:

ip: ""

So, in my hosts file on my Mac using Hostbuddy I add a new host and flush the DNS cache on my machine: tests.wp

Update WP Config

If you are running tests form the host computer then be sure to edit the wp-config.php file to that configuration. Here is what I do because the MySQL port is forwarded on the host computer:

/** MySQL hostname */
if( php_sapi_name() !== 'cli' || gethostname() == 'homestead' ) {
    define('DB_HOST', 'localhost');
} else {
    define('DB_HOST', '');

If you are running tests on the guest machine, Homestead, you do not need to do this.

Circle CI

If you need help with Circle CI this is a great resource