Skip to content

Run the integration tests in a separate wp-env site - #1132

Open
donnchawp wants to merge 7 commits into
trunkfrom
fix/wp-env-separate-tests-config
Open

donnchawp wants to merge 7 commits into
trunkfrom
fix/wp-env-separate-tests-config

Conversation

@donnchawp

@donnchawp donnchawp commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

wp-env has deprecated its built-in tests containers (tests-cli, tests-wordpress, tests-mysql) and warns about them on every wp-env start. Its README recommends a second config file used with --config instead, so that's what this does.

  • .wp-env.json sets "testsEnvironment": false, so make up starts only the development site on 8888.
  • .wp-env.tests.json is the test site on 8889, the port the old tests containers used. It has the same plugin mappings, mu-plugins and WPCACHEHOME as the development site, so the integration tests run in the same setup as before.
  • make test-integration starts the test site and runs PHPUnit in its cli container. make down and make destroy handle both sites.
  • A second checkout keeps its ports in .wp-env.override.json and .wp-env.tests.override.json (gitignored, e.g. { "port": 8890 }), which wp-env reads itself, so every make target uses them. For a one-off, WP_ENV_PORT and WP_ENV_TESTS_PORT override the files, from the environment or as make arguments. The Makefile only passes WP_ENV_PORT when a port is given, and drops an exported one for the test site so it doesn't take the development site's port.
  • make status shows whether each site is running, its URL, and its install path. wp-env names each checkout's containers after its directory plus a hash, like wp-env-wp-super-cache-1a2b3c4d, and the install path has the same name, so it tells you which containers belong to this checkout.

I also dropped WP_PHPUNIT__TESTS_CONFIG from make test-integration, because it was never used there. wp-env sets WP_TESTS_DIR to its own test library in the cli container, and tests/php/bootstrap-integration.php uses that before wp-phpunit. That library has its own config, which reads the WORDPRESS_DB_* variables wp-env sets. tests/php/wp-tests-config.php is still there for running the suite outside wp-env, and I've updated its comment and tests/php/README.md to say so.

Before you pull this

The old tests containers stay around until you remove them. If you followed the note in #1131 and stopped the old wp-super-cache project, there's nothing else to do. Otherwise make test-integration will fail on port 8889 until you stop it.

Testing

In a fresh worktree on spare ports, at 74b946e:

  • WP_ENV_TESTS_PORT=8895 make test-integration passes all 53 integration tests with no deprecation warning. The test site runs WordPress 7.1.5, has wpsc-loopback-fix.php in mu-plugins, and has WPCACHEHOME set.
  • WP_ENV_PORT=8894 make up starts only the three development containers, with wp-super-cache active.
  • make status WP_ENV_PORT=8894 WP_ENV_TESTS_PORT=8895 shows both sites running at their URLs.
  • WP_ENV_PORT=8894 WP_ENV_TESTS_PORT=8895 make down stops both sites, and exits 0 when the test site, or neither site, was ever started.
  • make test (the smoke suite) still passes all 160 tests.
  • With override files for 8894 and 8895, repeated make up and make test-integration stay on those ports. An exported WP_ENV_PORT=8896 moves only the development site, and make test-integration WP_ENV_TESTS_PORT=8897 moves only the test site. Without override files the sites use 8888 and 8889. The integration suite passed all 53 tests in each case (e518a9d).

74b946e renamed the port variables from PORT and TEST_PORT to WP_ENV_PORT and WP_ENV_TESTS_PORT, so a WP_ENV_PORT set in the shell is no longer overridden and an unrelated PORT export is ignored. Dry runs (make -n) show WP_ENV_PORT=8890, PORT=3000 and WP_ENV_TESTS_PORT=8891 give ports 8890, 8888 and 8891. The same commit lets make down succeed when the test site was never started; before, wp-env's "not initialized" exit failed the target. 56ce456 does the same for the development site, so make down also succeeds in a checkout where neither site has ever started.

Loopback requests on other ports

tests/dev/mu-plugins/wpsc-loopback-fix.php sends the site's requests to itself (preloader, WP-Cron, REST) to the wordpress container, but it only handled http://localhost:8888. On the test site (8889), or a checkout on other ports, those requests went to a port nothing listens on inside the container. 2357519 takes the port from the site's home URL instead.

DevLoopbackFixTest (2 new integration tests) checks that a request to the site's own port is sent to http://wordpress with the original Host, and that requests to other origins are left alone. The first fails on the old code, and the second fails if the fix rewrites every http://localhost URL. With it, the integration suite passes all 55 tests on a test site at 8895.

Plugin activation in worktrees

The second commit fixes a problem with worktrees. "plugins": [ "." ] mounts and activates the plugin under the checkout's folder name, so in a worktree the active plugin was named after the worktree. The copy the mapping puts at wp-content/plugins/wp-super-cache, which WPCACHEHOME points at, was inactive. In the main checkout both are the same folder, so you never saw it there.

The plugin is now mounted only through the mapping, and an afterStart lifecycle script runs wp plugin activate wp-super-cache, so plain wp-env start activates it too. The test site doesn't need it: the integration suite reinstalls WordPress and loads the plugin files itself.

In a fresh worktree, wp plugin list now shows wp-super-cache active and nothing named after the worktree. A second make up still succeeds, and the 53 integration tests still pass.

Base automatically changed from fix/wp-env-per-checkout to trunk December 1, 2026 17:04
wp-env has deprecated its built-in tests containers and warns on every
start. Turn them off and run the integration suite in a second environment
from .wp-env.tests.json on port 8889, as wp-env recommends. It keeps the dev
site's mappings and config.

Drop WP_PHPUNIT__TESTS_CONFIG from make test-integration: wp-env sets
WP_TESTS_DIR to its own test library and config, which the bootstrap uses
first, so tests/php/wp-tests-config.php only applies outside wp-env.
"plugins": [ "." ] mounts and activates the plugin under the checkout's
directory name, so in a worktree the active copy was named after the
worktree, and the copy the mapping put at wp-content/plugins/wp-super-cache,
which WPCACHEHOME points at, was inactive. Mount the plugin only through the
mapping and activate it after wp-env starts.
wp-env names each checkout's containers after its directory plus a hash.
make status shows both sites' state, URL and install path, whose name is
the compose project the containers belong to.
make down failed with Error 1 when the test site had never been started,
because wp-env exits 1 when asked to stop an uninitialised site. Ignore
that failure on the test-site stop.

The PORT and TEST_PORT make variables overrode any WP_ENV_PORT set in the
shell and picked up unrelated PORT exports. Use WP_ENV_PORT and
WP_ENV_TESTS_PORT instead, defaulting to 8888 and 8889.
@donnchawp
donnchawp force-pushed the fix/wp-env-separate-tests-config branch from 01655ee to 74b946e Compare December 1, 2026 17:05
WP_ENV_PORT=8890 make up only lasted one command: the next plain make up or
make test-integration went back to 8888/8889 and clashed with the main
checkout. A second checkout now puts its ports in .wp-env.override.json and
.wp-env.tests.override.json, which wp-env reads itself. The Makefile only
passes WP_ENV_PORT when a port is given, so the files decide otherwise, and
drops an exported WP_ENV_PORT for the test site so it doesn't take the
development site's port.
The wpsc-loopback-fix mu-plugin only rewrote requests to
http://localhost:8888. The test site runs on 8889, and a second checkout
now uses other ports from .wp-env.override.json, so their preloader,
WP-Cron and REST loopbacks went to a port nothing listens on inside the
container. Take the port from the site's home URL instead.
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.

1 participant