Skip to content

test(php): run PHPUnit in a separate wp-env config - #34

Merged
AnuragVasanwala merged 1 commit into
mainfrom
test/wp-env-tests-config
Oct 1, 2026
Merged

AnuragVasanwala merged 1 commit into
mainfrom
test/wp-env-tests-config

Conversation

@aryanjasala

Copy link
Copy Markdown
Member

@wordpress/env 11.16 deprecates the env block and the automatic tests environment, and prints a warning on every wp-env start. Its documented replacement is a second config file passed with --config.

Changes

  • .wp-env.tests.json defines the test environment: the plugin, the twentytwentytwo theme, port 8889, its own containers and database, and WP_DEBUG on.
  • .wp-env.json lists the plugin at the top level and sets testsEnvironment to false.
  • pretest:php starts the test environment and installs Composer dependencies in its cli container; test:php, pretest:php:coverage and test:php:coverage run there.
  • Docs and the scaffold skill describe the new setup and drop WP_ENV_TESTS_PORT.
  • The dev-tools feature already reads a top-level plugins list from .wp-env.json; a new test covers it (it fails if that fallback is removed).
  • .gitignore ignores .wp-env.tests.override.json.

Why not run the tests in the development environment's cli container: wp-env's wp-tests-config.php there uses the site's database and wp_ prefix, so the suite wipes the development site's content.

CI needs no change: ci-test-php runs npm run wp-env start and then npm run test:php, whose pretest hook starts the test environment, and WP_ENV_PHP_VERSION and WP_ENV_CORE apply to it too.

The dev-tools override still writes env.development, which wp-env still accepts; moving it to the new shape is a separate change for both starters.

Testing

  • npm run wp-env start and npm run test:php: no deprecation warnings; the test environment comes up on 8889
  • PHPUnit: 117 tests, 240 assertions; npm run test:php -- --filter UtilTest still passes arguments through
  • A post created on the development site survives the test run
  • WP_ENV_PHP_VERSION=8.3 npm run test:php runs on PHP 8.3.35 and passes
  • Jest 20 of 20, npm run lint passes

wp-env 11.16 deprecates the env block and the automatic tests environment.
The replacement it documents is a second config file, so
.wp-env.tests.json defines the test environment (port 8889, its own
containers and database, the plugin plus twentytwentytwo, WP_DEBUG on),
and .wp-env.json lists the plugin at the top level with testsEnvironment
false. pretest:php starts the test environment and the test:php scripts
run PHPUnit in its cli container.

A second config, not the development environment's cli container: wp-env's
wp-tests-config.php there uses the site's database and wp_ prefix, so the
suite would wipe the development site's content.

CI keeps working unchanged: WP_ENV_PHP_VERSION and WP_ENV_CORE apply to the
test environment too. The dev-tools feature already reads a top-level
plugins list; a test now covers it.
@AnuragVasanwala
AnuragVasanwala merged commit bc7f6d9 into main Oct 1, 2026
16 checks passed
@AnuragVasanwala
AnuragVasanwala deleted the test/wp-env-tests-config branch October 1, 2026 20:57
@aryanjasala aryanjasala mentioned this pull request Oct 1, 2026
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.

2 participants