Skip to content

Use wp-env for local PHPUnit test runs#1554

Merged
jtsternberg merged 4 commits into
developfrom
copilot/use-wp-env-for-phpunit-tests
Mar 3, 2026
Merged

Use wp-env for local PHPUnit test runs#1554
jtsternberg merged 4 commits into
developfrom
copilot/use-wp-env-for-phpunit-tests

Conversation

Copilot AI commented Mar 2, 2026

Copy link
Copy Markdown
Contributor

Running PHPUnit locally required manually installing the WordPress test suite via install-wp-tests.sh with a local MySQL database, despite wp-env already being available for E2E tests.

Changes

  • package.json: Updates phptests script to execute PHPUnit inside the wp-env tests-cli container instead of invoking vendor/bin/phpunit directly
- "phptests": "vendor/bin/phpunit"
+ "phptests": "wp-env run tests-cli vendor/bin/phpunit"

The local PHPUnit workflow becomes:

npm run env:start
npm run phptests
Original prompt

This section details on the original issue you should resolve

<issue_title>Use wp-env for local PHPUnit test runs</issue_title>
<issue_description>## 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</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: jtsternberg <1098900+jtsternberg@users.noreply.github.com>
Copilot AI changed the title [WIP] Use wp-env for local PHPUnit test runs Use wp-env for local PHPUnit test runs Mar 2, 2026
@jtsternberg jtsternberg marked this pull request as ready for review March 2, 2026 20:58
jtsternberg and others added 2 commits March 2, 2026 20:26
Without --env-cwd, wp-env runs commands from /var/www/html where
vendor/bin/phpunit doesn't exist as a relative path. Setting
--env-cwd=wp-content/plugins/cmb2 ensures PHPUnit resolves correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jtsternberg jtsternberg merged commit cdc3d68 into develop Mar 3, 2026
17 checks passed
@jtsternberg jtsternberg deleted the copilot/use-wp-env-for-phpunit-tests branch March 3, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use wp-env for local PHPUnit test runs

2 participants