PHPackages                             makeweb/wordpress-test-environment - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. makeweb/wordpress-test-environment

ActiveLibrary[Testing &amp; Quality](/categories/testing)

makeweb/wordpress-test-environment
==================================

Boot wordpress to test your code in an actual wordpress environment

1.1.2(7y ago)071MITPHP

Since Apr 10Pushed 7y ago1 watchersCompare

[ Source](https://github.com/makewebau/wordpress-test-environment)[ Packagist](https://packagist.org/packages/makeweb/wordpress-test-environment)[ RSS](/packages/makeweb-wordpress-test-environment/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (3)Versions (8)Used By (1)

Wordpress Test Environment
==========================

[](#wordpress-test-environment)

Easily pull Wordpress in to your plugin, library or package as a composer development dependency and test your code in an actual wordpress environment.

This package aims to support developers who wish to test code which depends on Wordpress in two key ways:

1. Boot wordpress to allow usage of wordpress database and global functions
2. Simulate actual HTTP requests to the wordpress application

Installation
------------

[](#installation)

From command line:

```
composer require --dev makeweb/wordpress-test-environment

```

Basic Usage
-----------

[](#basic-usage)

1. Once installed, Create a new database in your local MySQL installation.
2. Create a `.env` file in the base directory of the codebase you are testing and add the following to it (updating the credentials to match your newly created database and local environment):

```
DATABASE_NAME=database_name_here
DATABASE_USER=database_user_here
DATABASE_PASSWORD=database_password_here
DATABASE_HOST=127.0.0.1
SITE_URL=example.test

```

3. Initialise Wordpress in your parent test case class

Pass the relative path to the directory which contains your .env file into `loadEnvFrom()`

```
use MakeWeb\WordpressTestEnvironment\Wordpress;
use PHPUnit\Framework\TestCase as BaseTestCase;

class TestCase extends BaseTestCase;
{
    public function setUp()
    {
        $this->wordpress = (new Wordpress)
            ->loadEnvFrom(__DIR__.'/..');
    }
}

```

4. Usage in your tests

### Boot only

[](#boot-only)

If you simply wish to boot wordpress to allow access to the database and Wordpress global functions. Add the following lines to the start of your test.

#### In your test file

[](#in-your-test-file)

```
class MyPluginTest extends TestCase
{
    public function the_main_plugin_class_can_use_wordpress_global_functions()
    {
        $this->wordpress->boot();

        $this->assertEquals('http://example.test', (new MyPluginClass)->url());
    }
}

```

#### In your main plugin file or source code

[](#in-your-main-plugin-file-or-source-code)

Here we are just calling a native Wordpress function `get_site_url()`. If everything is set up correctly the test above will pass with the code below because `get_site_url()` has been defined by wordpress.

> Note: Make sure you are including the plugin file in your test bootstrap file manually or with an autoloader like composer

```
class MyPluginClass
{
    public function url()
    {
        return get_site_url();
    }
}

```

#### Test HTTP requests to your wordpress application

[](#test-http-requests-to-your-wordpress-application)

Sometimes your theme, plugin or library might actually handle HTTP requests (for example, if you are creating an API), or perhaps you just want to test the way your code affects the actual html output of the application. The `Wordpress` class exposes a get method which simulates an actual HTTP GET request to the given url. Wordpress, and your dependent code will be booted and executed as it would be in production. We don't need to call `$this->wordpress->boot()` when using the HTTP methods because it is done for us automatically.

#### In your test file

[](#in-your-test-file-1)

```
class MyPluginTest extends TestCase
{
    public function the_main_plugin_class_can_use_wordpress_global_functions()
    {
        // To boot the plugin which we are testing when booting wordpress, pass the relative path
        // to the main plugin file into the withPlugin() method. Installation and activation hooks
        // will not be called.
        $this->wordpress->withPlugin(__DIR__.'/../edd-sl-deployer.php');

        // Request the front page of the wordpress site and capture the result
        $response = $this->wordpress->get('/');

        // Assert that the response returned a 200 http status code
        $response->assertSuccessful();

        // Assert that our text was output in the html
        $response->assertSee('Hello World');
    }
}

```

#### In your plugin file or source code

[](#in-your-plugin-file-or-source-code)

```
/**
 * Plugin Name: Hello World Outputter
 * Plugin Description: An enterprise ready solution to output the text 'Hello World' on your website
 * Plugin URI: https://hello-world-outputter.com
 * Version: 1.0.0
 * Author: Andrew Feeney
**/

class MyPluginClass
{
    public function boot()
    {
        echo('Hello World');
    }
}

(new MyPluginClass)->boot();

```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~18 days

Total

6

Last Release

2863d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6f37a083266b9624a0b945354a06ec34e80e00816676179ba9065d626c7b5b6c?d=identicon)[MakeWeb](/maintainers/MakeWeb)

---

Top Contributors

[![AndrewFeeney](https://avatars.githubusercontent.com/u/13425337?v=4)](https://github.com/AndrewFeeney "AndrewFeeney (35 commits)")

### Embed Badge

![Health badge](/badges/makeweb-wordpress-test-environment/health.svg)

```
[![Health](https://phpackages.com/badges/makeweb-wordpress-test-environment/health.svg)](https://phpackages.com/packages/makeweb-wordpress-test-environment)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[orchestra/testbench

Laravel Testing Helper for Packages Development

2.2k39.1M32.1k](/packages/orchestra-testbench)[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M56](/packages/timacdonald-log-fake)[illuminate/testing

The Illuminate Testing package.

3315.6M113](/packages/illuminate-testing)[christophrumpel/missing-livewire-assertions

This package adds missing livewire test assertions.

149336.0k9](/packages/christophrumpel-missing-livewire-assertions)[calebdw/larastan-livewire

A Larastan / PHPStan extension for Livewire.

43482.4k3](/packages/calebdw-larastan-livewire)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
