Tests: Add unit test coverage for Readme_Utils trait - #1476
Conversation
|
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 If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
🟢 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,
.txtprecedence, 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.
740e295 to
595a719
Compare
|
Updated in
|
What?
Adds comprehensive unit test coverage for the
WordPress\Plugin_Check\Traits\Readme_Utilstrait intests/phpunit/tests/Traits/Readme_Utils_Tests.php.Why?
The
Readme_Utilstrait provides essential file-filtering and prioritization logic used across core plugin checks:WordPress\Plugin_Check\Plugin_ContextWordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Plugin_Readme_CheckWordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Plugin_Header_Fields_CheckWordPress\Plugin_Check\Checker\Checks\Plugin_Repo\Trademarks_CheckWhile other utility traits in
includes/Traits/(such asLanguage_Utils,Version_Utils,License_Utils, andAmend_DB_Base_Prefix) have dedicated unit tests intests/phpunit/tests/Traits/,Readme_Utilslacked 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.phpwith 16 tests and 16 assertions covering:test_filter_files_for_readme_with_empty_files_array: returns an empty array when given an empty list of files.test_filter_files_for_readme_with_no_readme_files: returns an empty array when no readme files are present in the list.test_filter_files_for_readme_with_root_readme_txt: correctly detects and returns root-levelreadme.txt.test_filter_files_for_readme_with_root_readme_md: correctly detects and returns root-levelreadme.mdwhen noreadme.txtexists.test_filter_files_for_readme_prefers_readme_txt_over_readme_md: verifies thatreadme.txttakes precedence overreadme.mdwhen both exist at root.test_filter_files_for_readme_case_insensitivity: verifies case-insensitive detection (README.TXT,README.MD,Readme.Txt,Readme.Md).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.test_filter_files_for_readme_with_root_and_nested_readmes: verifies root readme is selected while nested readmes are filtered out.test_filter_files_for_readme_ignores_non_matching_extensions: verifies that files likereadme.html,readme.doc,readme.rst, andreadme.phpare ignored.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:
Expected Output:
2. Run coding standards linter (PHPCS):
Expected Output:
3. Run static analysis (PHPStan):
Expected Output:
Use of AI Tools
includes/Traits/Readme_Utils.php, structuring test cases conforming toWP_UnitTestCasepatterns, and formatting testing instructions. Final implementation was reviewed, tested, and verified locally.