All Projects → humanmade → plugin-tester

humanmade / plugin-tester

Licence: other
Simple Docker image for running unit tests for WordPress plugins

Programming Languages

Dockerfile
14818 projects
PHP
23972 projects - #3 most used programming language
shell
77523 projects

humanmade/plugin-tester

Docker Pulls Docker Image Size (latest by date)

Simple Docker image for running unit tests for WordPress plugins.

To run the tests for your plugin, run this in your plugin directory:

docker run --rm -v "$PWD:/code" humanmade/plugin-tester

You will need phpunit/phpunit specified as a Composer dependency of your plugin. Additional arguments can be passed to PHPUnit on the CLI directly, e.g.:

docker run --rm -v "$PWD:/code" humanmade/plugin-tester --stop-on-error

Configuration

To configure PHPUnit, place a phpunit.xml.dist in the plugin root. You can alternatively use the command line arguments for PHPUnit for simpler tests.

Typically your tests directory in your plugin should include a bootstrap.php including at least the following:

<?php
require '/wp-phpunit/includes/functions.php';

tests_add_filter( 'muplugins_loaded', function () {
	require dirname( __FILE__ ) . '/../your-plugin-entry-point.php';
} );

require '/wp-phpunit/includes/bootstrap.php';

Continuous Integration with Travis

For Travis, the following minimal configuration will get your tests running:

services:
  - docker

before_script:
  - composer install

script:
  - docker run --rm -v "$PWD:/code" humanmade/plugin-tester

We recommend also caching the vendor directory:

cache:
  timeout: 1000
  directories:
    - vendor

Code Coverage

Plugin Tester includes pcov for test coverage, which is natively supported by PHPUnit 8+.

WordPress requires PHPUnit 7, so slight adjustments need to be made to PHPUnit to fix compatibility. Plugin Tester will do this automatically for you, provided you have pcov-clobber installed via Composer:

composer require --dev pcov/clobber

You can then set up coverage in your phpunit.xml.dist, or use the command-line flags:

docker run --rm -v "$PWD:/code" humanmade/plugin-tester --coverage-text --whitelist inc/
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].