Skip to content

Commit 5d86589

Browse files
committed
Match glob patterns with a slash against the full path
Makes --filter=*/Controller/* behave like --filter=/Controller/, so a glob containing a "/" is matched against the full path instead of the basename. Claude-Session: https://claude.ai/code/session_01J73DBF9SQvcgFnsBhr71cF
1 parent 7309ceb commit 5d86589

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/FileSystem/FilePathFilter.php‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,19 @@ private function matchesAllPatterns(string $filePath, array $patterns): bool
6161
/**
6262
* Three kinds of pattern are recognised:
6363
* - "tests" the basename ends in Test.php or TestCase.php
64-
* - contains "*" glob matched against the basename, e.g. *Repository.php
64+
* - contains "*" glob matched against the full path when it has a "/", else against the basename
6565
* - anything else substring matched anywhere in the full path, e.g. /Controller/
6666
*/
6767
private function matchesPattern(string $filePath, string $pattern): bool
6868
{
69-
$basename = basename($filePath);
70-
7169
if ($pattern === self::TESTS_KEYWORD) {
70+
$basename = basename($filePath);
7271
return str_ends_with($basename, 'Test.php') || str_ends_with($basename, 'TestCase.php');
7372
}
7473

7574
if (str_contains($pattern, '*')) {
76-
return fnmatch($pattern, $basename);
75+
$subject = str_contains($pattern, '/') ? $filePath : basename($filePath);
76+
return fnmatch($pattern, $subject);
7777
}
7878

7979
return str_contains($filePath, $pattern);

‎tests/FileSystem/FilePathFilter/FilePathFilterTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public static function provideData(): Iterator
4646

4747
yield 'path substring' => [['/Controller/'], ['/project/src/Controller/HomeController.php']];
4848

49+
yield 'path glob matches same as substring' => [['*/Controller/*'], ['/project/src/Controller/HomeController.php']];
50+
4951
yield 'basename glob' => [['*Repository.php'], ['/project/src/Repository/UserRepository.php']];
5052

5153
yield 'tests keyword' => [['tests'], [

0 commit comments

Comments
 (0)