Skip to content

Tests: Add unit test coverage for Readme_Utils trait - #1476

Merged
davidperezgar merged 4 commits into
WordPress:trunkfrom
noruzzamans:test/readme-utils-trait-tests
Sep 18, 2026
Merged

davidperezgar merged 4 commits into
WordPress:trunkfrom
noruzzamans:test/readme-utils-trait-tests

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What?

Adds comprehensive unit test coverage for the WordPress\Plugin_Check\Traits\Readme_Utils trait in tests/phpunit/tests/Traits/Readme_Utils_Tests.php.

Why?

The Readme_Utils trait provides essential file-filtering and prioritization logic used across core plugin checks:

  • WordPress\Plugin_Check\Plugin_Context
  • WordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Plugin_Readme_Check
  • WordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Plugin_Header_Fields_Check
  • WordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Trademarks_Check

While other utility traits in includes/Traits/ (such as Language_Utils, Version_Utils, License_Utils, and Amend_DB_Base_Prefix) have dedicated unit tests in tests/phpunit/tests/Traits/, Readme_Utils lacked isolated unit test coverage. Adding unit test coverage ensures its filtering logic, root-path resolution, and readme precedence rules remain reliable and regression-free.

How?

Introduced tests/phpunit/tests/Traits/Readme_Utils_Tests.php with 16 tests and 16 assertions covering:

  1. test_filter_files_for_readme_with_empty_files_array: returns an empty array when given an empty list of files.
  2. test_filter_files_for_readme_with_no_readme_files: returns an empty array when no readme files are present in the list.
  3. test_filter_files_for_readme_with_root_readme_txt: correctly detects and returns root-level readme.txt.
  4. test_filter_files_for_readme_with_root_readme_md: correctly detects and returns root-level readme.md when no readme.txt exists.
  5. test_filter_files_for_readme_prefers_readme_txt_over_readme_md: verifies that readme.txt takes precedence over readme.md when both exist at root.
  6. test_filter_files_for_readme_case_insensitivity: verifies case-insensitive detection (README.TXT, README.MD, Readme.Txt, Readme.Md).
  7. test_filter_files_for_readme_ignores_nested_readmes: verifies that readme files located in subdirectories (e.g. assets/readme.txt, vendor/package/readme.md, docs/readme.txt) are excluded.
  8. test_filter_files_for_readme_with_root_and_nested_readmes: verifies root readme is selected while nested readmes are filtered out.
  9. test_filter_files_for_readme_ignores_non_matching_extensions: verifies that files like readme.html, readme.doc, readme.rst, and readme.php are ignored.
  10. test_filter_files_for_readme_scenarios: data provider covering realistic file structures and various paths.

Note: This is a 100% test-only contribution with 0 modifications to production code.

Testing Instructions

1. Run the PHPUnit test suite:

phpunit tests/phpunit/tests/Traits/Readme_Utils_Tests.php

Expected Output:

PHPUnit 9.6.34 by Sebastian Bergmann and contributors.

................                                                  16 / 16 (100%)

Time: 00:00.015, Memory: 42.50 MB

OK (16 tests, 16 assertions)

2. Run coding standards linter (PHPCS):

composer lint tests/phpunit/tests/Traits/Readme_Utils_Tests.php

Expected Output:

. 1 / 1 (100%)
Time: 70ms; Memory: 18MB

3. Run static analysis (PHPStan):

composer phpstan

Expected Output:

[OK] No errors

Use of AI Tools

  • AI assistance: Yes
  • Model(s): Gemini 3.8 Flash High
  • Used for: Identifying test coverage gaps in includes/Traits/Readme_Utils.php, structuring test cases conforming to WP_UnitTestCase patterns, and formatting testing instructions. Final implementation was reviewed, tested, and verified locally.
Open WordPress Playground Preview

@noruzzamans
noruzzamans marked this pull request as ready for review September 17, 2026 11:28
@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: noruzzamans <noruzzaman@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.

🟢 Approval recommended

The test-only change has no blocking issues; only a minor style nit remains.

Pull request overview

Adds PHPUnit coverage for the Readme_Utils trait’s readme filtering and precedence behavior.

Changes:

  • Tests root detection, .txt precedence, casing, nesting, and invalid extensions.
  • Adds realistic data-driven path scenarios.
File summaries
File Description
tests/phpunit/tests/Traits/Readme_Utils_Tests.php Adds 16 unit tests for readme filtering.

Review note: Remove redundant PHPDoc blocks to follow project test-file guidance (nit).

Review details

Suppressed comments (1)

tests/phpunit/tests/Traits/Readme_Utils_Tests.php:6

  • The repository's test-file guidance explicitly excludes PHPDoc blocks for unit-test files, classes, and methods, but this file adds them throughout (including this header). Please remove the redundant test docblocks so the new test follows the established PHPUnit style and the project guideline.
/**
 * Tests for the Readme_Utils trait.
 *
 * @package plugin-check
 */
  • Files reviewed: 1/1 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@noruzzamans
noruzzamans force-pushed the test/readme-utils-trait-tests branch from 740e295 to 595a719 Compare September 17, 2026 13:14
@noruzzamans

Copy link
Copy Markdown
Contributor Author

Updated in f25c5d7b:

  • Removed redundant class, test method, and data provider PHPDoc blocks to align with repository conventions in tests/phpunit/tests/Traits/.
  • Retained @dataProvider annotations on parameterized tests.
  • Re-verified that all local PHPUnit tests (16/16), PHPCS, and PHPStan checks pass cleanly.

@davidperezgar
davidperezgar merged commit 32112b8 into WordPress:trunk Sep 18, 2026
28 checks passed
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.

4 participants