A Travis CI compatible unit testing architecture for WordPress plugins that utilizes WordPress core's official unit-testing framework and PHPUnit
- Automatically fires after every commit (or you can specificy certain branches)
- Downloads and sets up multiple versions of WordPress and PHP (as many as you want to specify)
- Downloads the WordPress unit testing framework if it doesn't already exist in the
tests/wordpress-tests
directory as a submodule - Runs all the tests and e-mails you on failure
- You have a WordPress plugin in GitHub (and thus a GitHub account)
- You posses basic knowledge of how to add and edit files using git
- Place
.travis.yml
file in your plugin's root folder (you may want to customize your build settings here) - Create a subfolder of your plugin called
tests/
and copy over theall.php
,bootstrap.php
, andphpunit.xml
files from this repo'stest/
folder - Customize the newly coppied
/tests/bootstrap.php
with the path to your plugin file - Activate Travis CI for your plugin
- Add tests to the
tests/
folder following the instructions below
First, set up the WP testing framework: http://make.wordpress.org/core/handbook/automated-testing/#installation
Then, add the environment variables to your .bashrc
file:
export WP_TESTS_DIR=~/wordpress-tests
export WP_CORE_DIR=~/path/to/wordpress-core
Finally, run the tests:
cd /path/to/your-plugin/tests
phpunit
- Each test file should live in the
tests/
folder and should be named in the format oftest_{name_of_test}.php
. - Each test file should contain a single class named in the form of
WP_Test_{name_of_test}
that extendsWP_UnitTestCase
. - Example Tests: WP Document Revisions
There's a separate branch setup.sh
which contains setup and config files which are pulled down on the fly when testing
- Fork the project to your account, make changes, and submit a pull request
- Integrate with your plugin and open issues / feature requests as you see fit
- 9/15/2012 - Removed
wordpress-tests
submodule in favor of core's SVN - 4/16/2012 - Initial commit of skelton based off of (legacy) core testing framework
- 6/30/2012 - Complete rewrite to rely on newer wordpress-tests framework and better PHPUnit integration
- Include git-based core testing framework as submodule when there's an official git version
- Ability to integrate with plugins as a submodule to allow for update
- Ability to customize configuration as pulled down from
setup.sh
Special thanks to @johnpbloch and @scribu for doing much of the legwork on the rewrite.