Summary
Running PHPUnit tests locally requires manually installing the WordPress test suite via tests/bin/install-wp-tests.sh with a local MySQL database. Since wp-env is already set up for Playwright E2E tests, we should leverage it for PHPUnit as well.
Current state
npm run phptests runs vendor/bin/phpunit directly, which requires a local WP test environment and MySQL
tests/bin/install-wp-tests.sh must be run manually with database credentials
- wp-env is already a dependency and configured with
npm run env:start
Proposal
Use wp-env run to execute PHPUnit inside the Docker container where WordPress and MySQL are already available:
npx wp-env run tests-cli vendor/bin/phpunit
Update npm run phptests to use this approach so the workflow becomes:
npm run env:start
npm run phptests
No local MySQL, no install script, no database credentials to manage.
Benefits
- Zero-config local test setup (just needs Docker)
- Same environment as E2E tests
- Consistent with WordPress core and Gutenberg testing patterns
- Removes the need for developers to run
install-wp-tests.sh locally
Summary
Running PHPUnit tests locally requires manually installing the WordPress test suite via
tests/bin/install-wp-tests.shwith a local MySQL database. Since wp-env is already set up for Playwright E2E tests, we should leverage it for PHPUnit as well.Current state
npm run phptestsrunsvendor/bin/phpunitdirectly, which requires a local WP test environment and MySQLtests/bin/install-wp-tests.shmust be run manually with database credentialsnpm run env:startProposal
Use
wp-env runto execute PHPUnit inside the Docker container where WordPress and MySQL are already available:Update
npm run phpteststo use this approach so the workflow becomes:No local MySQL, no install script, no database credentials to manage.
Benefits
install-wp-tests.shlocally