phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

Static Source Path Matching

Open dantleech opened this issue 2 months ago • 2 comments

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 avatar Oct 25 '25 12:10 dantleech

What is the status of this? Thanks.

sebastianbergmann avatar Dec 08 '25 07:12 sebastianbergmann

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.

dantleech avatar Dec 08 '25 09:12 dantleech