Skip to content

Tests: Add unit test suite for Ignore_Matcher utility - #1479

Merged
ernilambar merged 1 commit into
WordPress:trunkfrom
noruzzamans:test/ignore-matcher-unit-tests
Sep 20, 2026
Merged

ernilambar merged 1 commit into
WordPress:trunkfrom
noruzzamans:test/ignore-matcher-unit-tests

Conversation

@noruzzamans

@noruzzamans noruzzamans commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Description

This pull request introduces a dedicated, comprehensive PHPUnit test suite for the WordPress\Plugin_Check\Utilities\Ignore_Matcher class introduced in version 2.2.0 as part of the .pcpignore exclusion engine.

While Plugin_Request_Utility_Tests contains high-level integration checks, Ignore_Matcher contains core path normalization, glob-to-regex conversion, and wildcard matching algorithms that previously lacked direct, isolated unit test coverage.

Scope of Coverage (Ignore_Matcher_Tests.php)

The new test suite (tests/phpunit/tests/Utilities/Ignore_Matcher_Tests.php) covers all 5 methods and edge cases across 21 test cases:

  1. split_anchored_entries:

    • Empty entries arrays.
    • Skipping empty string elements.
    • Separating root-anchored entries (/docs, /build/*.map, /src/file?.js) from unanchored entries (vendor, *.log, node_modules).
    • Handling arrays with exclusively anchored or exclusively unanchored entries.
  2. is_file_in_ignored_directory:

    • Unanchored directory matching at arbitrary path depths (e.g. /vendor/autoload.php, /assets/vendor/lib.js).
    • Preventing false positive partial directory name matches (e.g. my-vendor and vendors not matching vendor).
    • Anchored directory matching strictly at the plugin root.
    • Rejecting nested directories of the same name for anchored rules (e.g. /sub/docs/ not matching /docs).
    • Glob wildcard matching with * (e.g. /build* matching /build-v1/ and /build-prod/).
    • Glob single-character wildcard matching with ? (e.g. /temp-? matching /temp-1/ and /temp-a/, but rejecting /temp-12/).
    • Graceful handling of empty entries and non-matching paths.
  3. is_file_ignored:

    • Unanchored file matching by suffix across directories (e.g. app.min.js).
    • Preventing partial file name matches (e.g. my-app.min.js and app.min.js.map not matching app.min.js).
    • Root-anchored file matching (/package.json).
    • Rejecting nested files for anchored rules (e.g. /assets/package.json not matching /package.json).
    • Wildcard matching with * (/*.map matching root maps without crossing directory boundaries).
    • Wildcard matching with ? (/data-?.json matching single-character variants and rejecting /data-10.json).
    • Graceful handling of empty entries and non-matching files.
  4. get_php_codesniffer_directory_ignore_pattern:

    • PHPCS regex pattern construction with ^ anchor and /* suffix.
    • Translation of glob wildcards (* to [^/]{0,}, ? to [^/]).
    • Proper escaping of regex metacharacters (-, [, ], .).
  5. get_php_codesniffer_file_ignore_pattern:

    • PHPCS regex pattern construction with ^ anchor and $ suffix.
    • Translation of glob wildcards and file extensions (/*.map, /file?.php).
    • Proper delimiter and character escaping.

Quality Gates Passed Locally

  • Syntax Check: php -l tests/phpunit/tests/Utilities/Ignore_Matcher_Tests.php (Passed with 0 errors)
  • PHP_CodeSniffer: composer lint / ./vendor/bin/phpcs (202/202 files, 100% clean, 0 errors, 0 warnings)
  • Static Analysis: composer phpstan (114/114 files, 100% clean, Level 5, 0 errors)
  • Execution: All 21 test methods passing.
  • Contribution Type: 100% Test-Only (0 production code modifications).
Open WordPress Playground Preview

@noruzzamans
noruzzamans marked this pull request as ready for review September 20, 2026 05:50
@github-actions

github-actions Bot commented Sep 20, 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. 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>
Co-authored-by: davidperezgar <davidperez@git.wordpress.org>

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

@davidperezgar

Copy link
Copy Markdown
Member

Looks good to me. The new tests provide focused coverage for Ignore_Matcher’s anchored/unanchored matching, wildcard behavior, negative cases, and PHPCS pattern generation. All CI checks are passing. Nice addition—thanks!

@noruzzamans

Copy link
Copy Markdown
Contributor Author

Looks good to me. The new tests provide focused coverage for Ignore_Matcher’s anchored/unanchored matching, wildcard behavior, negative cases, and PHPCS pattern generation. All CI checks are passing. Nice addition—thanks!

Thanks for the review and kind words, @davidperezgar! Glad to contribute.

@ernilambar
ernilambar merged commit 09b65a8 into WordPress:trunk Sep 20, 2026
29 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.

3 participants