WordPress functional tests without a server

Embedded WP version 0.0.1 is out!

WordPress tests without a WordPress installation?

I’ve began working on a new Codeception module extending the possibilities of wp-browser to be able to run functional tests on WordPress plugins and themes removing the need for a running MySQL server and WordPress installation.
The driving need is making modular and atomic development a reality and allowing me to tap into WordPress code base without the overhead of having to set up a server.
This is not a replacement of the WPLoader module part of the wp-browser suite but an additional possibility.
The result of this first effort is on GitHub tagged 0.0.1.

A code example (aka “the 5′ install”)

After requiring the library in composer

composer require lucatume/wp-embedded

I will wait for Composer to finish pulling the required components and will then scaffold the tests structure

codecept bootstrap

Presuming I’m developing a plugin called “My Plugin” with a main file called my-plugin.php in the plugin root folder I will configure the functional suite to use the EmbeddedWp module

# Codeception Test Suite Configuration
# Suite for functional (integration) tests
# Emulate web requests and make application process them
# Include one of framework modules (Symfony2, Yii2, Laravel5) to use it

class_name: FunctionalTester
        - \Helper\Functional
        - EmbeddedWp
            mainFile: my-plugin.php
              - my-plugin.php

build the testing classes

codeception build

and create a first test for the plugin functions

wpcept generate:wpunit functional myPlugin

Given the plugin code

 * Plugin Name: My Plugin
 * Plugin URI: http://theAverageDev.com
 * Description: My test plugin
 * Version: 1.0
 * Author: theAverageDev
 * Author URI: http://theAverageDev.com
 * License: GPL 2.0

require_once 'vendor/autoload.php';

register_activation_hook(__FILE__, function () {
    update_option('myplugin_did_activate', 'yes');

if (!function_exists('myplugin_slashit')) {
    function myplugin_slashit($string)
        return trailingslashit($string);

The tests will not differ from the ones used in WPLoader or WordPress automated testing suite.


class myPluginTest extends \WP_UnitTestCase

    protected $backupGlobals = false;

    public function setUp()
        // before

        // your set up methods here

    public function tearDown()
        // your tear down methods here

        // then

    public function test_slashit()
        $this->assertEquals('foo/', myplugin_slashit('foo'));

    public function test_activation()
       $this->assertEquals('yes', get_option('myplugin_did_activate'));


to have the tests run without a server at all
Serverless tetst

I appreciate your input