Skip to content

Conversation

@dantleech
Copy link
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.

@dantleech dantleech force-pushed the gh-6114-source-map-no-fs-2 branch from e6c0737 to 31dd5e9 Compare October 25, 2025 12:59
],
),
),
],
Copy link
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
Owner

What is the status of this? Thanks.

@dantleech
Copy link
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.

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

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