Skip to content

Run PHPUnit on pull requests - #23

Merged
obenland merged 5 commits into
trunkfrom
ci/phpunit
Sep 28, 2026
Merged

obenland merged 5 commits into
trunkfrom
ci/phpunit

Conversation

@obenland

@obenland obenland commented Sep 28, 2026 •

Copy link
Copy Markdown
Member

Summary

The PHPUnit suite in tests/ wasn't run in CI, which is how the #20 bootstrap regression reached trunk unnoticed (fixed in #22). This adds a workflow that runs it on every PR, speeds up the suite, and hardens both workflows.

PHPUnit workflow

  • Uses the MySQL server preinstalled on the runner instead of a service container, which saves about 45s.
  • Sparse-checks out WordPress/wordpress-develop (src plus the test library).
  • PHP 8.5 (same as PHPCS), with PHPUnit 9.6 and the PHPUnit Polyfills installed via Composer.
  • The job takes about 30s.

Faster tests (CI: 3.6s → 1.2s, locally 2.7s → 0.4s)

  • Outgoing HTTP is blocked in the test bootstrap. The AJAX tests fire admin_init, where core's update checks made three real requests to api.wordpress.org, adding about 0.45s per test.
  • The security tests build their users, posts and meta once per class in wpSetUpBeforeClass(), instead of running about 500 queries before every test. Each test still runs in a rolled-back transaction, and five random-order runs all pass.

Workflow security (both workflows)

  • permissions: contents: read. The repo default for GITHUB_TOKEN is write, and PHPUnit runs PR code.
  • persist-credentials: false, so the token isn't left in .git/config for later steps.
  • Actions are pinned to full commit SHAs (actions/checkout v7.0.1, setup-php 2.37.2).
  • Steps have descriptive names.

Testing

  • Both workflows pass on this PR (23 tests, 57 assertions).

🤖 Generated with Claude Code

Add a workflow that runs the PHPUnit suite against a MySQL service,
using wordpress-develop for WordPress core and the test library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 28, 2026 21:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

obenland and others added 4 commits September 28, 2026 16:31
Use the runner's preinstalled MySQL instead of a service container,
sparse-check out wordpress-develop, and move to actions/checkout@v7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Block outgoing HTTP in tests: the AJAX tests fire admin_init, whose core
update checks made three real requests to api.wordpress.org per test.
Build the security tests' users, posts and meta once per class in
wpSetUpBeforeClass() instead of ~500 queries before every test.

Suite runtime drops from 2.7s to 0.4s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Restrict GITHUB_TOKEN to read-only contents (the repo default is
write), don't persist the token in the checkout, and pin actions to
full commit SHAs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@obenland
obenland merged commit cca02b1 into trunk Sep 28, 2026
2 checks passed
@obenland
obenland deleted the ci/phpunit branch September 28, 2026 21:45
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