wpenv – Docker based testing environment for WordPress

24. September 2017 Note , , , ,

I am contributing to WP-CLI as a committer.

We sometimes need to run PHPUnit and Behat with the specific PHP version which I am not usually using.

And also, we sometimes need to run them for the specific WordPress version.

So, I developed a Docker based testing environment.


How to run Behat for WP-CLI command

If you want to run Behat for specific PHP version + WordPress version in your local machine, you can do it like following.

$ git clone git@github.com:wp-cli/core-command.git
$ cd core-command
$ curl -L https://raw.githubusercontent.com/miya0001/wpenv/master/run.sh | bash -s 5.6 4.6
$ docker exec -it wpenv bash

This example will start Docker container with the PHP 5.6 and WordPress 4.6 and login into the container.

Then you can run Behat like following.

$ composer update
$ vendor/bin/behat

How to run PHPUnit for WordPress plugin

PHPUnit is pre-installed in my Docker image.

So, you can use this solution for testing your WordPress plugin.

$ wp scaffold plugin my-plugin
$ cd wp-content/plugins/my-plugin

Then run Docker in the directory.

$ curl -L https://raw.githubusercontent.com/miya0001/wpenv/master/run.sh | bash -s 7.1 4.8
$ docker exec -it wpenv bash

Finally, run phpunit in the container.

$ phpunit


Actually, I was using phpenv on my Mac, but I often have something problem with it.

I am hoping it would help you.

Leave a Reply

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