Skip to content

test: deslop and fix PHPUnit Tests - #189

Closed
justlevine wants to merge 6 commits into
WordPress:dev/deps-scaffoldfrom
justlevine:tests/fix-phpunit-errors
Closed

test: deslop and fix PHPUnit Tests#189
justlevine wants to merge 6 commits into
WordPress:dev/deps-scaffoldfrom
justlevine:tests/fix-phpunit-errors

Conversation

@justlevine

@justlevine justlevine commented May 17, 2026

Copy link
Copy Markdown
Contributor

What

This PR relocates PHPUnit tests to tests/phpunit, then deslops the internals so tests pass.

Why

Tests were failing due to compounding AI-slop around the TestCase.

How

  • Updated TestCase to extend the correct WP_UnitTestCase, and use the built-in methods.
  • Fixed an caused by calling a method from a trait, instead of from a class implementing the trait.
  • Cleaned up the various filter-stubbing and generation slop. Not everything, just what was getting in the way of fixing the tests.
  • Moved problematic and test-case-specific abilities out of DummyAbility and into the ability that uses them.
  • Added setExpectedIncorrectUsage() to the tests that should have it.

(The goal was not to audit all of the existing tests, just to fix the central issues causing all the failures).

Copilot AI review requested due to automatic review settings May 17, 2026 21:07
@github-actions

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: justlevine <justlevine@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Relocates the PHPUnit suite from tests/Unit & tests/Integration to tests/phpunit/..., replaces the bespoke _doing_it_wrong capture helpers with the polyfilled setExpectedIncorrectUsage() API, and rewrites the base TestCase to extend WP_UnitTestCase directly. A number of test fixtures (especially in DummyAbility) are slimmed down and migrated to in-test registration via register_ability_in_hook(). Configuration files (phpunit.xml.dist, phpstan.neon.dist, .phpcs.xml.dist, composer.json, wp-env JSON, GitHub workflows) are updated to the new layout and to newer dep versions. Also includes unrelated scaffolding cleanup (dependabot, SECURITY.md, gitignore/gitattributes, PR template, removed README-INITIAL.md).

Changes:

  • Relocate test suite to tests/phpunit/ and replace custom assertDoingItWrongTriggered() helper with setExpectedIncorrectUsage(); slim down DummyAbility fixtures with per-test ability registration.
  • Update tooling configs (PHPUnit/PHPCS/PHPStan paths, wp-env split into .wp-env.json and .wp-env.test.json, pinned action SHAs, Node 22, new composer script names).
  • Minor production touches: RequestRouter calls is_sensitive_key on ErrorLogMcpObservabilityHandler instead of the trait; DiscoverAbilitiesAbility adds PHPCS ignore comments for unused parameters.

Reviewed changes

Copilot reviewed 50 out of 103 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/phpunit/** (most files) Moved from tests/, reformatted, switched to setExpectedIncorrectUsage, in-test ability registration.
tests/TestCase.php, tests/Unit/PluginTest.php Removed old locations.
tests/phpunit/TestCase.php New base class extending WP_UnitTestCase, simpler setup, no _doing_it_wrong capture.
tests/phpunit/Fixtures/Dummy*.php Re-added at new path; DummyAbility no longer includes resources with old-meta/whitespace/invalid-annotations fixtures (moved into specific tests).
tests/phpunit/Stubs/WpCli*.php New stub classes/utilities for WP-CLI in tests.
tests/phpunit/bootstrap.php Updated paths and now requires the plugin entry directly.
tests/phpstan/wp-cli-stubs.stub Added PHPStan stub for WP_CLI.
includes/Transport/Infrastructure/RequestRouter.php Switched is_sensitive_key call from the trait to ErrorLogMcpObservabilityHandler.
includes/Abilities/DiscoverAbilitiesAbility.php Added PHPCS ignore comments for unused params.
composer.json Renamed scripts (lint, format, phpstan), removed wpackagist repo/plugin-check, bumped phpcompatibility-wp to ^3.0.0-alpha, updated autoload-dev path.
phpunit.xml.dist Updated bootstrap, suite paths, coverage output; dropped mcp-adapter.php from coverage.
phpstan.neon.dist Reformatted, dropped abilities-api sibling scan, switched to local stub file, bumped max PHP to 8.5.
.phpcs.xml.dist Removed plugin-check ruleset, updated prefix list, set min WP to 6.9, exclude _output.
.wp-env.json / .wp-env.test.json Split dev and test environments; new test env on port 8889.
package.json Node 22 requirement; new wp-env:test/wp-env:cli scripts; updated @wordpress/* deps and overrides block.
.github/workflows/*.yml Updated to newer pinned action SHAs and cli env target; PHPStan no longer checks out abilities-api.
.github/dependabot.yml, .github/PULL_REQUEST_TEMPLATE.md, SECURITY.md, .npmrc New project-scaffolding files.
.gitignore, .gitattributes, .prettierrc.js, .prettierignore, .nvmrc, docs/guides/testing.md, CONTRIBUTING.md, README-INITIAL.md Misc scaffolding/docs alignment.
Comments suppressed due to low confidence (1)

tests/phpunit/Unit/Core/McpAdapterConfigTest.php:425

  • Typo in the comment: trailing 4 at the end of "test error handling4". Should be just "test error handling".

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread composer.json
Comment thread includes/Transport/Infrastructure/RequestRouter.php
@codecov

codecov Bot commented May 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.44%. Comparing base (d0ac080) to head (a17e03e).

Additional details and impacted files
@@             Coverage Diff              @@
##              trunk     #189      +/-   ##
============================================
+ Coverage     88.25%   88.44%   +0.19%     
  Complexity     1243     1243              
============================================
  Files            54       53       -1     
  Lines          4035     4033       -2     
============================================
+ Hits           3561     3567       +6     
+ Misses          474      466       -8     
Flag Coverage Δ
unit 88.44% <100.00%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@justlevine
justlevine force-pushed the tests/fix-phpunit-errors branch from 6f57bf5 to 9afa2f2 Compare May 17, 2026 21:29
@justlevine justlevine changed the title tests: deslop and fix PHPUnit Tests test: deslop and fix PHPUnit Tests May 17, 2026
@justlevine
justlevine changed the base branch from trunk to dev/deps-scaffold May 17, 2026 21:58
@justlevine
justlevine deleted the branch WordPress:dev/deps-scaffold May 19, 2026 10:00
@justlevine justlevine closed this May 19, 2026
@justlevine

Copy link
Copy Markdown
Contributor Author

Wow our GH settings on this repo are absolute crap... This should have just auto-changed to the base branch.

Will ping someone to handle alongside #186

@justlevine

Copy link
Copy Markdown
Contributor Author

Moved to #193

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