Skip to content

Testing

PHPUnit tests run against the real WordPress + WooCommerce test suite (not mocks), following the same pattern as vendor/barberklingen/base-plugin.

Prerequisites

  • A local checkout of wordpress-develop with its own wp-tests-config.php pointing at a dedicated test database (see wp-tests-config-sample.php in that checkout).
  • That test database's MySQL server running and reachable.
  • Composer dependencies installed, including dev dependencies:
composer install

Configuration

Copy .env.sample to .env and point it at your wordpress-develop checkout:

cp .env.sample .env
WP_DEVELOP_DIR="/path/to/wordpress-develop/"

.env is git-ignored — every developer/machine sets its own path.

No other configuration is needed to run the suite: tests/bootstrap.php sets fixed test credentials (DIXA_MIM_TOOLS_API_KEY / DIXA_MIM_TOOLS_API_SECRET) for the order-status endpoint tests, so they don't depend on real .env secrets being present.

Running

vendor/bin/phpunit

Run a single test file or method the usual PHPUnit way:

vendor/bin/phpunit tests/Modules/OrderStatus/OrderLookupServiceTest.php
vendor/bin/phpunit --filter test_finds_order_by_order_number_and_email

Structure

Tests mirror the src/ layout, e.g. src/Modules/OrderStatus/OrderLookupService.phptests/Modules/OrderStatus/OrderLookupServiceTest.php.

  • Tests with no WordPress DB dependency (e.g. RateLimiterTest, BasicAuthGuardTest) extend Barberklingen\BasePlugin\Tests\BaseTest (plain PHPUnit).
  • Tests that need real WooCommerce orders or a dispatched REST request (e.g. OrderLookupServiceTest, REST/RouteControllerTest) extend the global WP_UnitTestCase, which wraps each test in a rolled-back DB transaction.

Troubleshooting

  • "Can't connect to MySQL server": the test database isn't running — start it before running the suite.
  • rest_no_route from a REST integration test: this package has no standalone plugin bootstrap of its own (see Architecture) — Dixa::init() normally runs from a separate site-level bootstrap that isn't present in an isolated test run, so REST route tests register their controller directly instead of relying on it.