So in my workflow I use the following:
- WP-CLI to manage WordPress from commandline.
- PHPUnitTest for testing WordPress themes and plugin.
- Nodejs for javascript related stuff.
- Grunt for automating builds and release.
For this to work under gitlab and gitlab-ci I need a docker which would essentially have the following:
- PHP-7.0 with CLI - for unittesting.
- Nodejs - for using npm and grunt.
- WordPress Test - an environment for making WordPress Plugin/Theme unit testing a breeze.
In this attempt, I am creating a docker which would have the following installed by default, so that I don't have to everytime.
PHP-7.0NodejsandnpmGrunt-CLIinstalled globally.Bowerinstalled globally.Gitvim wget zip unzip subversion mysql-client libmcrypt-dev libmysqlclient-dev zip unzip openssh-client gettextPHPUnit- PHAR Install.Composer- PHAR Install.WP-CLIsetup for WordPress unit testing: (/usr/local/bin/wp)- Downloaded WordPress latest.zip with proper environment setup. -
WP_CORE_DIR - SVN-ed WordPress test libraries with proper environment setup. -
WP_TESTS_DIR
- Downloaded WordPress latest.zip with proper environment setup. -
For WP_UnitTest the following environment variables are set:
WP_CORE_DIR"/tmp/wordpress/"WP_TESTS_DIR"/tmp/wordpress-tests-lib"WP_VERSION"4.8"WP_TESTS_TAG"tags/4.8"
So if you have used WP-CLI to scaffold your PHP_UnitTest (which you should), you are covered. The install will run to only setup the databse variables and the test-config file.
# Our base image
image: wpquark/wptest-php-nodejs-grunt:latest
# mysql service
services:
- mysql
# Select what we should cache
cache:
paths:
- vendor/
- node_modules/
before_script:
# Install npm dependencies
- npm install
# Install composer
- composer install
# Install WordPress PHPUnit Test
- 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_MULTISITE: "0"
# We test on php7
# default job
default-job:
tags:
- wordpress
script:
- grunt
except:
- tags
# release job on tag
release-job:
tags:
- wordpress
script:
- grunt release
artifacts:
paths:
- build/wpq-social-press.zip
only:
- tagsThe above is just a sample. In real world, we use multiple stages with test > build > deploy (staging > production) strategy. Check gitlab documentation for information on that.