You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a dedicated GitHub Actions workflow (.github/workflows/validate-phpunit-cleanup-pr.yml) to automatically validate that PHPUnit test files added or updated in pull requests comply with the core test modernization specification (#65208, #53010).
Automated Checks Performed:
File Path Hierarchy: Validates that test files adhere to the standardized directory structure under tests/phpunit/tests/:
For class methods: tests/phpunit/tests/wp-[includes|admin]/[SubFolder/]*Class_Under_Test/FunctionUnderTest[OptionalSubsetIndicator]Test.php
For procedural functions: tests/phpunit/tests/wp-[includes|admin]/[SubFolder/]*Functions_FileName/FunctionUnderTest[OptionalSubsetIndicator]Test.php
Namespace Compliance: Ensures all test files declare a valid PSR-4 namespace starting with WordPress\Tests\... that strictly maps to the directory structure.
Class Naming & Granularity:
Enforces single-class-per-file granularity.
Verifies that class names end with Test and match their filename exactly (FunctionUnderTest[OptionalSubsetIndicator]Test).
Support File Exclusions: Automatically skips test helper/harness files (such as base.php), mock fixtures, and data directories.
Testing Instructions
Review workflow trigger configuration and permissions in .github/workflows/validate-phpunit-cleanup-pr.yml.
Open or update a pull request modifying test files under tests/phpunit/tests/ to trigger the Validate PHPUnit Test Cleanup Files workflow.
Verify that test files following the specification pass with success summaries, while non-compliant files or namespaces produce clear, actionable error logs.
AI Disclosure
AI assistance: Yes
Tool(s): JetBrains Junie
Model(s): Gemini 2.5 Flash
Used for: Developing the GitHub Actions workflow definition and JavaScript validation logic for test structure compliance.
Adds a GitHub Actions workflow to validate changed PHPUnit tests against WordPress’s planned test modernization requirements, supporting preparation for #65208 and #53010.
Changes:
Checks test paths, namespaces, class names, and single-class-per-file structure.
Validates class-level @covers annotations and links covered symbols to source files.
Skips deleted files and selected support/fixture paths, then reports validation results.
Refactor validation logic for PHPUnit test files to enforce stricter directory structure and naming conventions.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The workflow can cancel unrelated PR validations, reject compliant tests during source lookup, and accept procedural layouts or PHP namespaces that violate validation requirements.
Updated concurrency group logic and added validation for procedural test file locations. Enhanced source file linking for WordPress tests.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The workflow has unresolved validation defects that accept invalid namespaces and coverage targets, reject valid tests, and impose migration requirements on unrelated test changes.
No open issues 🎉
8 previously missed issues
In code that hasn't changed since last review
Resolve CamelCase paths to kebab-case source files
CamelCase path segments cannot resolve back to hyphenated source filenames: Functions_PostTemplate/GetTheTitleTest.php covering ::get_the_title cannot find src/wp-includes/post-template.php. The same issue rejects Walker_PageDropdown/StartElTest.php covering Walker_PageDropdown::start_el, whose source is class-walker-page-dropdown.php. Add CamelCase-to-kebab-case variants in this shared helper while retaining the existing candidates.
Resolve class source files beyond generated basenames
This source-file guessing rejects existing core classes whose names do not map directly to their filenames. For example, _WP_Dependency becomes -wp-dependency, missing src/wp-includes/class-wp-dependency.php; _WP_Editors is declared in class-wp-editor.php, which none of these candidates produces either. Correctly organized tests for these classes will fail with "No matching source file found." Resolve classes using a declaration-to-file index or explicit mappings for these exceptions rather than relying exclusively on generated basenames.
The annotation value is interpolated as regex syntax rather than a literal PHP symbol: @covers ::wp_mkdir_. in WpMkdirPTest.php matches function wp_mkdir_p(...), although the annotated function does not exist. Escape both function and class targets before constructing these regular expressions so malformed annotations cannot pass source validation.
The function lookup does not distinguish global functions from class methods. A Functions_class-wp-post/FilterTest.php fixture with @covers ::filter passes because this regex finds WP_Post::filter() in class-wp-post.php, although no global filter() exists. Make symbol verification scope-aware so procedural annotations only match global functions and method annotations only match methods of the specified class.
Resolve inherited methods when validating coverage
Requiring the method declaration in the same file as the target class rejects inherited methods. For example, the existing font-family tests cover WP_REST_Font_Families_Controller::get_context_param (tests/phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php:172), but that method is inherited through WP_REST_Posts_Controller from WP_REST_Controller. Moving this test into the prescribed subclass directory will still fail source validation. Resolve the target class's inheritance chain when checking methods instead of requiring a textual declaration in its own source file.
This applies the new layout requirements to every modified PHPUnit file immediately, including unmigrated tests such as tests/phpunit/tests/functions.php, which still declares Tests_Functions without a namespace. Adding an ordinary regression test there will now fail this workflow unless the entire file is migrated. Since this is preparation for a later modernization project, please gate enforcement to opted-in cleanup PRs or otherwise define a staged rollout so unrelated test fixes remain possible.
This accepts namespaces such as WordPress\TestsWrong\WP_Includes\Functions_functions: the prefix check passes, and slicing off the first two segments discards TestsWrong without validating it. An otherwise valid file can therefore pass outside the required WordPress\Tests\... namespace. Require the trailing namespace separator in the prefix check.
Only the first class-level @covers annotation is parsed, and all subsequent target/name/source checks use that one value. A docblock containing @covers ::wp_mkdir_p followed by @covers ::nonexistent_function therefore passes: the second annotation is inside the allowed docblock but its target is never validated. Collect and validate every annotation, or explicitly reject additional targets if the cleanup specification permits only one.
The reason will be displayed to describe this comment to others. Learn more.
Please limit validation to files that opt into the new layout. I ran the proposed script with two real trunk paths marked as modified. An ordinary edit to tests/phpunit/tests/adminbar.php produced 10 errors, and an edit to tests/phpunit/tests/canonical/category.php produced nine. Both would require an unrelated rename and namespace change just to update an assertion.
Could you show one existing-file edit passing unchanged and one opted-in file with a bad name failing? That would let us review the naming workflow separately from the 7.3 whole-file renames, as agreed in Trac #65208.
AI review · gpt-6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Trac ticket: https://core.trac.wordpress.org/ticket/65208
Prep work for when we start the project after 7.2
Description
Adds a dedicated GitHub Actions workflow (
.github/workflows/validate-phpunit-cleanup-pr.yml) to automatically validate that PHPUnit test files added or updated in pull requests comply with the core test modernization specification (#65208, #53010).Automated Checks Performed:
tests/phpunit/tests/:tests/phpunit/tests/wp-[includes|admin]/[SubFolder/]*Class_Under_Test/FunctionUnderTest[OptionalSubsetIndicator]Test.phptests/phpunit/tests/wp-[includes|admin]/[SubFolder/]*Functions_FileName/FunctionUnderTest[OptionalSubsetIndicator]Test.phpWordPress\Tests\...that strictly maps to the directory structure.Testand match their filename exactly (FunctionUnderTest[OptionalSubsetIndicator]Test).base.php), mock fixtures, and data directories.Testing Instructions
.github/workflows/validate-phpunit-cleanup-pr.yml.tests/phpunit/tests/to trigger theValidate PHPUnit Test Cleanup Filesworkflow.AI Disclosure