dev-master 2013-07-27 13:29 UTC



Testing tool with fixture feature for WordPress plugin development, based on the PHPUnit.

##Installation composer.json

    "require": {
        "ackintosh/wptestcase": "dev-master"
$ php composer.phar install


  • Install this tool.
$ cd wordpress/wp-content/plugins
$ php composer.phar install
  • Set up tables for testing that was changed to 'wptest_' a prefix.

Set up tables

  • Prepare the fixture file written in YAML.


  post_title: Test post title 1
  post_content: Test post content 1
  post_status: publish
  post_title: Test post title 2
  post_content: Test post content 2
  post_status: publish

Available parameters are the same as 'wp_insert_post' function.

Function Reference/wp insert post

  • Write test code.
class SamplePluginTest extends Ackintosh\WPTestCase

    // The table prefix for testing can be changed.
    // protected $test_prefix = 'wptest_';

    public function test_insert_post()
        // Loading data.
        $this->setPostFixture(__DIR__ . '/post_fixture.yml');

        // We can get the post data that inserted by the fixture function.
        $posts = get_posts();

        // Can use all features in PHPUnit.
        $this->assertEquals($expect, $result);
  • Run the tests.
$ vendor/bin/phpunit


  • PHP 5.3 or greater