Skip to content

Run PHPUnit in CI without wp-env#3

Merged
louwie17 merged 3 commits intotrunkfrom
ci/phpunit-without-wp-env
Apr 30, 2026
Merged

Run PHPUnit in CI without wp-env#3
louwie17 merged 3 commits intotrunkfrom
ci/phpunit-without-wp-env

Conversation

@louwie17
Copy link
Copy Markdown
Contributor

Summary

  • Adds bin/install-wp-tests.sh which downloads WP core, checks out the WP PHPUnit suite via SVN, generates wp-tests-config.php, creates the test DB, downloads WooCommerce latest-stable, and symlinks the repo into the plugins directory
  • Replaces the phpunit CI job's Node.js + wp-env setup with a MySQL service container + the install script + composer run test-unit — no Docker-in-Docker required
  • Adds a test-unit composer script alias (mirrors the WCA convention)
  • Updates the bootstrap docblock to document both the wp-env (local) and bare-PHP (CI) execution paths

bin/check and the local wp-env workflow are unchanged.

Test plan

  • PHPUnit job passes in CI
  • bin/check still works locally

🤖 Generated with Claude Code

louwie17 and others added 3 commits April 30, 2026 11:42
Replaces the Docker/wp-env-based PHPUnit job with a lightweight setup
that installs WordPress, WooCommerce, and the WP PHPUnit test suite
directly on the runner — no Node.js or container startup required.

Changes:
- bin/install-wp-tests.sh: new script that downloads WP core and the
  WP PHPUnit suite via SVN, generates wp-tests-config.php, creates the
  test DB, downloads WooCommerce latest-stable, and symlinks the plugin
- .github/workflows/ci.yml: phpunit job now spins up a MySQL 8 service
  and runs install-wp-tests.sh + composer run test-unit instead of
  wp-env start + wp-env run tests-cli
- composer.json: add test-unit script alias (mirrors WCA convention)
- tests/integration/bootstrap.php: update docblock to document both
  the wp-env (local) and bare-PHP (CI) execution paths

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…n tests

The WP test harness only loads the front-end; wp-admin/includes/plugin.php
(which defines activate_plugin()) is never required. This caused the
bootstrap to return early before calling WC_Install::install(), so
create_roles() never ran and manage_woocommerce was never added to the
administrator role on a fresh database.

The wp-env environment masked the bug because WooCommerce was pre-installed
via the afterStart lifecycle script, so roles were already in the DB.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Two related issues prevented manage_woocommerce from being visible to
current_user_can() on a clean database:

1. WP_Roles singleton is stale after create_roles() runs.
   WP_Roles is initialized lazily; when WC_Install::create_roles() adds
   capabilities the in-memory singleton does not reflect the changes for
   any code path that already held a reference.  Resetting
   $GLOBALS['wp_roles'] = null and calling wp_roles() forces a fresh read
   from the database.  (Same pattern WCA uses; see WP trac #28374.)

2. WC's own check_version() hook (plugins_loaded) ran WC_Install::install()
   before our HPOS options were set, then our install call was skipped
   because the db_version already matched.  Setting woocommerce_db_version
   in muplugins_loaded after loading WC prevents the premature auto-install;
   we delete the option again in init (priority 0) so our controlled call to
   WC_Install::install() -- with HPOS enabled -- actually runs.

Also fixes bin/install-wp-tests.sh to split host:port when calling
mysqladmin, which requires separate --host and --port flags.

Verified: 256/256 tests pass on a fresh MySQL 8 database (CI path) and
via wp-env (local path).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@louwie17 louwie17 force-pushed the ci/phpunit-without-wp-env branch from 93fd374 to 63f8247 Compare April 30, 2026 09:43
@louwie17 louwie17 merged commit 6e78ebc into trunk Apr 30, 2026
2 checks passed
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