PHPUnit tests for the backend PHP code in includes/ and src/. This guide follows the WooCommerce guide to unit tests.
For JavaScript unit tests, see tests/js/README.md. For an overview of all test suites, see tests/README.md.
- Start the WordPress container:
pnpm run up(orpnpm run up:recreatefor first-time setup)- This auto-starts shared infrastructure (database, phpMyAdmin) if not already running
- Once the containers are up, run tests from the plugin root directory:
pnpm run test:php- Run PHP unit testspnpm run test:php-watch- PHP tests in watch modepnpm run test:php-coverage- PHP tests with coverage
- Run a single test class or method:
docker compose exec -u www-data wordpress bash -c \
"cd /var/www/html/wp-content/plugins/woocommerce-payments && \
vendor/bin/phpunit --configuration phpunit.xml.dist --filter 'TestClassName::test_method_name'"
- From the plugin directory, run
composer installif you have not already:
$ composer install
- Install WordPress and the WP Unit Test lib using the
bin/install-wp-tests.shscript. From the plugin root directory type:
$ bin/install-wp-tests.sh <db-name> <db-user> <db-password> [db-host]
Tip: try using 127.0.0.1 for the DB host if the default localhost isn't working.
- Run the tests from the plugin root directory using
$ ./vendor/bin/phpunit