2017 © Pedro Peláez
 

library wordpress-testing-harness

Makes testing plugins and themes with WordPress and Composer much easier

image

rosio/wordpress-testing-harness

Makes testing plugins and themes with WordPress and Composer much easier

  • Thursday, June 12, 2014
  • by ben-rosio
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 0 % Grown

The README.md

WordPress Testing Harness

This library is meant to make it easier to test plugins and themes with the WordPress runtime via PHPUnit.
This is basically just a rewrite of kurtpayne/wordpress-unit-tests., (*1)

Usage:

  1. Add this library, your testing library, and your WordPress deployment of choice to your plugin or themes composer.php:, (*2)

        "autoload-dev": {
            "psr-4": {
                "Plugin\\SomePlugin\\": "tests/"
            }
        },
        "require-dev": {
            "phpunit/phpunit": "~3.7",
            "rosio/wordpress-testing-harness": "dev-master",
            "johnpbloch/wordpress": "~3.8"
        },
    

    You don't actually have to include WordPress, and instead have it download to the correct folder during testing (which means you can then test multiple versions of WordPress easily), but it's recommended to add one for easy local testing., (*3)

  2. Configure your phpunit.xml.dist, (*4)

    
    <phpunit backupGlobals="false"
             beStrictAboutTestSize="true"
             backupStaticAttributes="false"
             bootstrap="tests/bootstrap.php"
             colors="true"
             convertErrorsToExceptions="true"
             convertNoticesToExceptions="true"
             convertWarningsToExceptions="true"
             processIsolation="false"
             stopOnFailure="false"
             syntaxCheck="false"
    >
        <testsuites>
            <testsuite name="Application Test Suite">
                <directory suffix="Test.php">./tests/</directory>
            </testsuite>
        </testsuites>
    </phpunit>
    
    
  3. Configure your phpunit's tests/bootstrap.php file:, (*5)

    <?php
    
    require_once __DIR__ . '/../vendor/autoload.php';
    
    $bootstrapper = new Rosio\WordPressTestingHarness\Bootstrapper(array(
        'bootstrap-path' => __FILE__,
    
        'db-name' => 'wp_test',
        'db-user' => 'root',
        'db-pass' => 'root',
        'db-host' => 'localhost',
        'db-prefix' => 'wptests_',
        'db-charset' => '',
        'db-collate' => '',
        'wplang' => '',
    
        'wordpress-path' => __DIR__ . '/../wordpress',
        'domain' => 'wp.localhost',
        'admin-email' => 'admin@example.org',
        'blog-title' => 'Tests',
        'admin-password' => 'admin',
    
        'always-reinstall' => true,
    
        'php-binary' => 'php',
        'testdata-path' => __DIR__ . '/../data',
    ));
    
    // Require in plugin
    require __DIR__ . '/../index.php';
    
  4. Write your first test!, (*6)

    <?php
    namespace Plugin\SomePlugin;
    
    use WP_UnitTestCase;
    use \Mockery as m;
    
    class MainPluginTest extends WP_UnitTestCase
    {
        public function setUp()
        {
    
        }
    
        public function tearDown()
        {
            m::close();
        }
    
        public function testPluginIsCreated()
        {
            $this->assertInstanceOf('Plugin\SomePlugin\MainPlugin', getSomePlugin());
        }
    }
    

The Versions

12/06 2014

dev-master

9999999-dev

Makes testing plugins and themes with WordPress and Composer much easier

  Sources   Download

The Requires

 

12/06 2014

v1.1.1

1.1.1.0

Makes testing plugins and themes with WordPress and Composer much easier

  Sources   Download

The Requires

 

11/06 2014

v1.1.0

1.1.0.0

Makes testing plugins and themes with WordPress and Composer much easier

  Sources   Download

The Requires

 

10/06 2014

v1.0.2

1.0.2.0

Makes testing plugins and themes with WordPress and Composer much easier

  Sources   Download

The Requires

 

10/06 2014

v1.0.1

1.0.1.0

Makes testing plugins and themes with WordPress and Composer much easier

  Sources   Download

The Requires

 

10/06 2014

v1.0.0

1.0.0.0

Makes testing plugins and themes with WordPress and Composer much easier

  Sources   Download

10/06 2014

v0.0.1

0.0.1.0

Makes testing plugins and themes with WordPress and Composer much easier

  Sources   Download