Skip to content

Static Source Path Matching#6398

Closed
dantleech wants to merge 15 commits intosebastianbergmann:mainfrom
dantleech:gh-6114-source-map-no-fs-2
Closed

Static Source Path Matching#6398
dantleech wants to merge 15 commits intosebastianbergmann:mainfrom
dantleech:gh-6114-source-map-no-fs-2

Conversation

@dantleech
Copy link
Copy Markdown
Contributor

@dantleech dantleech commented Oct 25, 2025

This PR is a proof-of-concept for statically matching paths without traversing the filesystem during the test run. It replaces #6146 and uses the webmozarts/glob package.

Would fix #6114


The primary goal is to ensure that the source mapper needn't iterate over all included directories recursively whenever the source map is required to validate if a file belongs to the mapped files or not - for example when a deprecation is encountered PHPUnit needs to know if the deprecation was issued from source code within the project's responsiblity - i.e. source that is mapped.

We can determine if a file is within the included source by converting the glob-patterns in the <directory> element to regexes. Currently the <directory> element in <include> and <exclude> has the attributes prefix and suffix and we also have <file> which specifies a single file.

This is more complicated than it could be:

  • Current matching/traversal logic depends on PHP's glob function - the implementation of which is not consistent across platforms and which has a number of rarely-used operators which while not common, would present a B/C break if they were removed.

We can expect the following breaks in behavior:

  • Differences in the more esoteric syntax between the internal glob function and the
    webmozarts library. Note that the behavior of glob is also dependent on
    the platform making it hard-to-impossible to lock down the behavior
    completely (for reference linux man page for glob).
  • Consequently the behavior of phpunit/php-file-iterator will not exactly match the results of the static matching logic.

Things to consider:

  • Making this an experiemental "feature flag"
  • Updating the phpunit/php-file-iterator to use the same package so as to be consistent.
  • Implementing the logic within PHPUnit rather than using an external package.
  • Documenting the glob syntax.

Comment thread composer.json Outdated
Comment thread src/TextUI/Configuration/README.md Outdated
Comment thread tests/unit/TextUI/SourceFilterTest.php Outdated
Comment thread tests/unit/TextUI/SourceFilterTest.php Outdated
@dantleech dantleech force-pushed the gh-6114-source-map-no-fs-2 branch from e6c0737 to 31dd5e9 Compare October 25, 2025 12:59
Comment thread tests/unit/TextUI/SourceFilterTest.php Outdated
],
),
),
],
Copy link
Copy Markdown
Contributor Author

@dantleech dantleech Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test, that passes on main, seems more like a bug, e.g. the directory path a/c/Z** wil include a/c/PrefixSuffix.php

@dantleech dantleech force-pushed the gh-6114-source-map-no-fs-2 branch from c9cf387 to 5107851 Compare October 25, 2025 13:19
@dantleech dantleech mentioned this pull request Oct 25, 2025
6 tasks
@sebastianbergmann sebastianbergmann added this to the PHPUnit 13.0 milestone Oct 27, 2025
@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented type/performance Issues related to resource consumption (time and memory) labels Oct 27, 2025
@sebastianbergmann
Copy link
Copy Markdown
Owner

What is the status of this? Thanks.

@dantleech
Copy link
Copy Markdown
Contributor Author

dantleech commented Dec 8, 2025

Hey, basically this is a proposal - and it should work but would need more time invested in testing, exploring the behavior and perhaps adding more test cases and as above, to consider:

  • Should this be a"feature flag"?
  • Do we want/need to update the phpunit/php-file-iterator to use the same package so as to be consistent.
  • Do we want to use the external package or "vendor" the code within PHPUnit.
  • Do we want to document the (new) glob syntax, and I guess, the difference between the old and new.

@sebastianbergmann sebastianbergmann force-pushed the main branch 2 times, most recently from f9c751b to 23f7b4a Compare December 31, 2025 15:57
@sebastianbergmann sebastianbergmann force-pushed the main branch 2 times, most recently from 8e693d6 to 2d1b2b2 Compare December 31, 2025 16:41
@sebastianbergmann sebastianbergmann removed this from the PHPUnit 13.0 milestone Jan 24, 2026
@sebastianbergmann
Copy link
Copy Markdown
Owner

I started working on a new library, file-filter, for this. This allows to work on this outside of PHPUnit and makes it easy to use the the functionality in both PHPUnit and php-code-coverage.

Help on this new library would be much appreciated. The most obvious thing to do right now would be to add more test cases.

@dantleech
Copy link
Copy Markdown
Contributor Author

I started working on a new library, file-filter

that looks great!

Help on this new library would be much appreciated.

I have to regretfully back away a bit, I've already got a number of unfinshed open-source plates spinning and I'm not sure I can add more value then what you've already provided there. But feel free to reach out with any specifics I can help with.

@sebastianbergmann
Copy link
Copy Markdown
Owner

Superseded by #6493.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

type/enhancement A new idea that should be implemented type/performance Issues related to resource consumption (time and memory)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reimplement SourceFilter::includes() to not depend on SourceMapper and to not perform filesystem traversal

2 participants