Skip to content

ci: make npm run test:php actually work#2

Closed
epeicher wants to merge 6 commits into
trunkfrom
fix/php-tests
Closed

ci: make npm run test:php actually work#2
epeicher wants to merge 6 commits into
trunkfrom
fix/php-tests

Conversation

@epeicher

Copy link
Copy Markdown
Collaborator

Summary

A fresh clone had no way to run PHP tests — vendor/bin/phpunit didn't exist, and CI had to curl the WP test installer every run. This wires up a Composer-based toolchain so local dev and CI share one binary and one setup flow.

  • composer.json + composer.lock pin phpunit/phpunit ^9.6 and yoast/phpunit-polyfills ^2.0
  • bin/install-wp-tests.sh is the canonical wp-cli scaffold installer, pinned so CI no longer curls it
  • package.json: test:phpvendor/bin/phpunit …; new test:php:install wraps the SVN installer with local defaults
  • tests/phpunit/bootstrap.php loads the Composer autoload first (polyfills) and points the "missing test suite" error at test:php:install
  • .github/workflows/ci.yml drops the phpunit:9 tool pin, adds composer install, calls the committed installer
  • DEVELOPMENT.md documents the one-time setup (svn, MySQL, composer install, npm run test:php:install)

Test plan

  • PHPUnit job on CI passes on both PHP 8.1 and 8.2 matrix legs
  • Composer install step completes cleanly on CI
  • bin/install-wp-tests.sh populates /tmp/wordpress-tests-lib
  • Local run after composer install + npm run test:php:install + npm run test:php succeeds

A fresh clone had no way to run PHP tests — `vendor/bin/phpunit`
didn't exist and the test suite script had to be curl'd in CI every
run. Wire up a Composer-based toolchain so local and CI share the
same binary and setup flow.

- composer.json / composer.lock: pin phpunit/phpunit ^9.6 and
  yoast/phpunit-polyfills ^2.0 (what WP's test suite needs on
  PHPUnit 9). PHP version constraint matches the plugin's header
  (>=7.4).
- bin/install-wp-tests.sh: commit the canonical wp-cli scaffold
  installer (pinned from v2.4.0) so CI no longer has to curl it and
  local runs work the same way.
- package.json: `test:php` runs `vendor/bin/phpunit …`;
  `test:php:install` is a convenience wrapper around the SVN-based
  installer with sensible local defaults (root / no password /
  127.0.0.1 / latest).
- tests/phpunit/bootstrap.php: require vendor/autoload.php first so
  phpunit-polyfills loads. Also improves the "tests not installed"
  error message to point at `test:php:install`.
- .github/workflows/ci.yml: drop the phpunit:9 tool pin (Composer
  provides it), add a `composer install` step, and call the
  committed `bin/install-wp-tests.sh` instead of the inline curl.
- .gitignore: exclude /vendor.
- DEVELOPMENT.md: document the one-time setup — `composer install`,
  MySQL running, SVN present, then `npm run test:php:install`.
The old lockfile held only macOS-arm64 entries for `@esbuild/*`, so
CI's Linux runner couldn't resolve them and `npm ci` bailed with
"Missing: @esbuild/linux-x64@0.28.0 from lock file" (and 20+ more).
A clean `npm install` writes the lockfile with every platform's
optional binary, which is what npm 7+ expects.
Composer installed on my local PHP 8.5 pulled `doctrine/instantiator
2.1.0` into the lock, which requires PHP 8.4+. CI runs PHP 8.1 and
8.2 — the lock failed to resolve and `composer install` bailed.

Setting `config.platform.php = "8.1"` in composer.json forces the
resolver to pick versions compatible with the oldest CI matrix leg.
Regenerated composer.lock drops instantiator back to 2.0.0 (PHP
7.4+) while keeping PHPUnit 9.6.34.
Fresh `npm install` on Node 24 / npm 11 left 28 entries in
package-lock.json marked `"extraneous": true` — mostly
`@esbuild/<platform>` optional binaries. `npm ci` on CI (Node 20)
refused to install those because their platform metadata doesn't
match the Linux runner, even though they're nominally optional.

`npm prune` after install drops them cleanly from the lockfile,
leaving only entries the dep tree actually references.
Mirror fix/lint-errors 9cfe655 — regenerate package-lock.json on
node:20-alpine so CI's `npm ci` resolves cleanly. Replaces the
previous Mac-generated-then-pruned lockfile that left npm short of
legitimate `esbuild@0.28.0` entries.
@epeicher

Copy link
Copy Markdown
Collaborator Author

Closed in favour of #7

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