Skip to content

Add Infection mutation testing for PHP unit tests - #4913

Draft
stracker-phil wants to merge 23 commits into
dev/developfrom
dev/add-mutation-tests
Draft

stracker-phil wants to merge 23 commits into
dev/developfrom
dev/add-mutation-tests

Conversation

@stracker-phil

Copy link
Copy Markdown
Collaborator

Changelog: (none - dev tooling)

Description

🎯 The goal

Line coverage shows which code the unit tests run, but not whether they check it. Mutation testing makes small changes to the source code and reports each change that no test detects. This PR adds Infection for the PHP unit tests in tests/PHPUnit, for local runs and in CI.

✅ The fix

  • Setup: Infection has its own Composer project and config in tests/infection/, apart from the plugin dependencies. It runs only in DDEV. tests/infection/README.md explains how to run it and how to read the results.
  • CI: a new "Mutation tests" job mutates only the lines that a branch changes against dev/develop. Escaped mutants show as warning annotations on the changed lines. The job does not fail because of escaped mutants, so it never blocks a merge.
  • Brain Monkey: Patchwork reads source files past Infection's stream wrapper, so it would compile the original file instead of the mutant. During Infection runs only, tests/PHPUnit/bootstrap.php gives the mutant code to Patchwork.
  • DDEV: the local site now runs PHP 8.2, because Infection needs it. The plugin still supports PHP 7.4, and the CI matrix still tests it.
  • CI trigger: the CI workflow now also runs on pull_request, so pull requests from forks get checks too.

🧪 Tests

Infection first runs the full unit test suite in random order and stops on any failure or STDERR output. Some tests depended on test order or on time, or wrote to STDERR. These tests are fixed, and two tests that were always skipped are removed. No production code changes.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The changes in this pull request can be previewed and tested using a WordPress Playground instance.
WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

🔗 Test this pull request with WordPress Playground

What's included:

  • ✅ WordPress (latest)
  • ✅ WooCommerce (latest)
  • ✅ PayPal Payments plugin v4.2.2-pr4913-46453642961-ga6a1fc3 (built from this PR)

Login credentials:

  • Username: admin
  • Password: password

Plugin Details:

  • Version: 4.2.2-pr4913-46453642961-ga6a1fc3
  • Commit: 99aa6d5
  • Artifact: woocommerce-paypal-payments-4.2.2-pr4913-46453642961-ga6a1fc3

💡 The demo environment resets each time you refresh. Perfect for testing!

🔄 This link updates automatically with each new commit to the PR.

⚠️ This URL is valid for 30 days from when this comment was last updated.


🤖 Auto-generated for commit 99aa6d5 • Last updated: 2026-11-30T15:47:42.781Z

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