Skip to content

Use wp-env for local PHPUnit test runs #1553

Description

@jtsternberg

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions