Skip to content

Testing

Tests use PHPUnit 9.x against a real WordPress + WooCommerce environment managed by subscribed/wp-testing-kit.

Setup

1. Copy and configure the test environment file:

cp .env.sample .env.testing

Edit .env.testing and set WP_DEVELOP_DIR to your local WordPress source checkout.

2. Initialise the test database:

composer run test:init

This creates the WordPress test tables in a temporary database.

3. Run the suite:

composer run test
# or directly:
vendor/bin/wp-test

4. Reset (wipe and re-initialise):

composer run test:reset

Bootstrap behaviour

tests/bootstrap.php sets up a WordPress integration environment. Key env vars:

Variable Default Purpose
WP_DEVELOP_DIR .env.testing Path to wordpress-develop checkout
WP_TESTS_DIR /tmp/wordpress-tests-lib Path to test library
WC_LOAD "" Set to "1" to load WooCommerce
WC_INSTALL "" Set to "1" to run WooCommerce install (slow)
ACTIVE_PLUGINS "" Comma-separated plugin main files to activate

Writing tests

Extend Barberklingen\BasePlugin\Tests\BaseTest (or plain WP_UnitTestCase) for integration tests that need a database. Use plain PHPUnit TestCase for pure unit tests.

use Barberklingen\BasePlugin\Tests\BaseTest;

class MyTest extends BaseTest {
    public function test_something(): void {
        // WordPress and WooCommerce are available here
    }
}

Place test files under tests/ with a Test.php suffix — they are picked up automatically by phpunit.xml.