Fix: recognise Windows drive-letter absolute paths in FileFinder#36
Open
joshdaugherty wants to merge 1 commit into
Open
Fix: recognise Windows drive-letter absolute paths in FileFinder#36joshdaugherty wants to merge 1 commit into
joshdaugherty wants to merge 1 commit into
Conversation
A Windows absolute path starts with a drive letter (C:\...), not DIRECTORY_SEPARATOR, so FileFinder treated PHPUnit's absolute <source> paths as relative, prepended getcwd(), and dropped them — leaving `pest --mutate` with nothing to mutate on Windows. Adds an isAbsolutePath() helper (drive-letter + UNC aware, mirroring PHPUnit) and a FileFinder test.
603b448 to
33b45d7
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What:
Description:
On Windows, running
pest --mutatewithout an explicit--pathfinds nothing to mutate — it prints0 Mutations for 0 Files created, even with a coverage driver installed.When you don't pass
--path, the plugin takes its directories from PHPUnit's<source>configuration, and PHPUnit gives those as absolute paths.FileFinder::separateDirectoriesAndFiles()then decides whether each path is relative like this:On Windows,
DIRECTORY_SEPARATORis\, but an absolute Windows path begins with a drive letter such asC:\project\app— not\. So this treats the path as relative and addsgetcwd()in front of it, producing a path that doesn't exist:C:\project\C:\project\app.is_dir()is then false, the directory is skipped, and the finder has nothing to scan.This only happens on Windows. On Linux and macOS an absolute path starts with
/, which isDIRECTORY_SEPARATOR, so the check works and CI never sees it. Passing a relative--path=appalso avoids it, which is the usual workaround.The fix. Add a small
isAbsolutePath()check that also treats a drive-letter path (C:\...orC:/...) and a UNC path (\\server\share) as absolute — the same way PHPUnit decides this itself. Relative paths still getgetcwd()added in front, so--path=appand similar keep working, and nothing changes on Linux or macOS.Tests. A new
tests/Unit/Support/FileFinderTest.php:/..., UNC, and Windows drive letters in upper and lower case) and for relative paths (includingC:foo, which is relative, and an empty string), so the Windows cases are covered even when the suite runs on Linux;FileFinder::files()against a real absolute source directory and confirms it finds the fixture files. This fails on the current4.xon Windows (it finds nothing) and passes with the fix.Notes.
/, and relative paths are still resolved againstgetcwd().str_starts_with($x, DIRECTORY_SEPARATOR)check is also used inFileFinder::buildPathsToIgnore()(lines 63 and 69 on4.x), so a Windows drive-letter path in the ignore list has the same problem and may not be excluded. That is less serious than the source-path case — a missed exclusion rather than zero mutations — has no reproduction yet, and fixing it properly also means reworking the nearbygetcwd()handling, so I left it out to keep this PR focused. Flagging it here; happy to follow up.composer test:lint,test:types,test:refacto,test:type-coverage, andtest:unitall pass.