Automated WordPress PHPUnit Testing on GitLab CI

In a previous post, i showed us how to set up automated PHP testing on GitLab CI.

If you are a WordPress developer and has a test suite already for your plugin, theme or WordPress powered web application and would love to use the GitLab CI to run it; my .gitlab-ci.yml below will come in handy.

# Select what we should cache
cache:
  paths:
  - vendor/

services:
- mysql

before_script:
# Install git, the php image doesn't have installed
- apt-get update -yqq
- apt-get install git -yqq

# instll the required packages for the running CI tests
- apt-get -yqqf install vim wget zip unzip subversion mysql-client libmcrypt-dev libmysqlclient-dev --fix-missing

# Install mysql driver
- docker-php-ext-install mysqli pdo_mysql mbstring

# Install Xdebug
- pecl install xdebug

# PHP extensions
- docker-php-ext-enable mysqli pdo_mysql mbstring xdebug

# Install composer
- curl -sS https://getcomposer.org/installer | php

# Install all project dependencies
- php composer.phar install

- bash bin/install-wp-tests.sh wordpress_test root mysql mysql $WP_VERSION

variables:
  # Configure mysql service (https://hub.docker.com/_/mysql/)
  MYSQL_DATABASE: wordpress_tests
  MYSQL_ROOT_PASSWORD: mysql
  WP_VERSION: latest
  WP_MULTISITE: "0"

# We test PHP5.6
test:php5.6:
  image: php:5.6
  script:
  - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clove --colors=never

# We test PHP5.6 with multisite
test:php5.6:multisite:
  variables:
   WP_VERSION: latest
   WP_MULTISITE: "1"
  image: php:5.6
  script:
  - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clove --colors=never

# We test PHP7
test:php7:
  image: php:7
  script:
  - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --colors=never


# We test PHP7 with multisite
test:php7:multisite:
  variables:
   WP_VERSION: latest
   WP_MULTISITE: "1"
  image: php:7
  script:
  - vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clove --colors=never

Note

The YAML configuration above assume you have your WordPress unit test created with WP CLI hence the bash bin/install-wp-tests.sh wordpress_test root mysql mysql $WP_VERSION. Otherwise replace it whith your own WordPress PHP test setup.

Also, it will run three jobs.
Feel free to make modifications to meet your use case.

La Fin!

Don’t miss out!
Subscribe to My Newsletter
Invalid email address