Skip to content

65208 action namespace validations - #13908

Open
pbearne wants to merge 15 commits into
WordPress:trunkfrom
pbearne:65208-action-namespace-validations
Open

pbearne wants to merge 15 commits into
WordPress:trunkfrom
pbearne:65208-action-namespace-validations

Conversation

@pbearne

@pbearne pbearne commented Oct 1, 2026

Copy link
Copy Markdown

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:

  • 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

  1. Review workflow trigger configuration and permissions in .github/workflows/validate-phpunit-cleanup-pr.yml.
  2. Open or update a pull request modifying test files under tests/phpunit/tests/ to trigger the Validate PHPUnit Test Cleanup Files workflow.
  3. 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.

@github-actions

github-actions Bot commented Oct 1, 2026 •

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.

Core Committers: Use this line as a base for the props when committing in SVN:

Props pbearne.

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


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

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.

🟡 Changes recommended

The workflow rejects compliant procedural tests while accepting class-directory mismatches, incorrect namespace casing, truncated target names, and invalid directory hierarchies.

5 open issues
What changed in this PR

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.
File Description
.github/​workflows/​validate-phpunit-cleanup-pr.yml Adds the PR-triggered workflow and embedded JavaScript validation logic.

Review effort: Balanced

pbearne and others added 2 commits November 4, 2026 18:14
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>

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.

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>

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.

🔵 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

Medium severity Resolve CamelCase paths to kebab-case source files

.github/​workflows/​validate-phpunit-cleanup-pr.yml:114

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.

Medium severity Resolve class source files beyond generated basenames

.github/​workflows/​validate-phpunit-cleanup-pr.yml:171

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.

Medium severity Escape annotation targets before building regexes

.github/​workflows/​validate-phpunit-cleanup-pr.yml:210

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.

Medium severity Match covered symbols by scope

.github/​workflows/​validate-phpunit-cleanup-pr.yml:210

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.

Medium severity Resolve inherited methods when validating coverage

.github/​workflows/​validate-phpunit-cleanup-pr.yml:214

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.

Medium severity Stage layout enforcement for unmigrated tests

.github/​workflows/​validate-phpunit-cleanup-pr.yml:245

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.

Medium severity Require an exact Tests namespace prefix

.github/​workflows/​validate-phpunit-cleanup-pr.yml:311

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.

Medium severity Validate every @​covers annotation

.github/​workflows/​validate-phpunit-cleanup-pr.yml:376

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.

4 resolved since last review

Review effort: Balanced

@lancewillett lancewillett left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In review

Development

Successfully merging this pull request may close these issues.

3 participants