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-developwith its ownwp-tests-config.phppointing at a dedicated test database (seewp-tests-config-sample.phpin that checkout). - That test database's MySQL server running and reachable.
- Composer dependencies installed, including dev dependencies:
Configuration¶
Copy .env.sample to .env and point it at your wordpress-develop checkout:
.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¶
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.php → tests/Modules/OrderStatus/OrderLookupServiceTest.php.
- Tests with no WordPress DB dependency (e.g.
RateLimiterTest,BasicAuthGuardTest) extendBarberklingen\BasePlugin\Tests\BaseTest(plain PHPUnit). - Tests that need real WooCommerce orders or a dispatched REST request (e.g.
OrderLookupServiceTest,REST/RouteControllerTest) extend the globalWP_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_routefrom 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.