wpstarter/wp-testbench

A tool to set up a WordPress test environment for PHPUnit testing

v1.0.2 2023-06-05 04:26 UTC

This package is auto-updated.

Last update: 2024-11-05 07:46:43 UTC


README

WpTestbench is a tool used to set up a WordPress test environment for PHPUnit testing, in order to test your plugin.

Installation

Install testbench via composer

composer require wpstarter/wp-testbench --dev

Install WordPress

./vendor/bin/wp-testbench-install <db-name> <db-user> [db-pass] [db-host] [wp-version] [--skip-database-creation]

Update phpunit.xml

<phpunit 
    ...
    bootstrap="./vendor/wpstarter/wp-testbench/bootstrap.php"

>
    ...
    <php>
        <server name="WP_TESTBENCH_PLUGIN" value="your-plugin.php"/>
        ...
    </php>
</phpunit>

Custom wp-config.php

<phpunit>
    <php>
        <server name="WP_TESTBENCH_CONFIG" value="your-config.php"/>
    </php>
</phpunit>

That's all then you can run the PHPUnit test

./vendor/bin/phpunit