From e5906a50cf5b31c301bd1ec07cc8a4a3a743ac74 Mon Sep 17 00:00:00 2001 From: Mozex Date: Tue, 3 Nov 2026 18:08:16 +0300 Subject: [PATCH] fix(tia): match test files under wildcard suite directories (#1980) Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> --- src/Plugins/Tia/TestPaths.php | 20 +++++++-- .../Features/Tia/WildcardSuiteDirectories.php | 45 +++++++++++++++++++ .../Tia/overlays/wildcard-suite/phpunit.xml | 20 +++++++++ 3 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 tests/Features/Tia/WildcardSuiteDirectories.php create mode 100644 tests/Fixtures/Tia/overlays/wildcard-suite/phpunit.xml diff --git a/src/Plugins/Tia/TestPaths.php b/src/Plugins/Tia/TestPaths.php index 101a876e..26e96fbd 100644 --- a/src/Plugins/Tia/TestPaths.php +++ b/src/Plugins/Tia/TestPaths.php @@ -35,10 +35,12 @@ final readonly class TestPaths foreach ($configuration->testSuite() as $suite) { foreach ($suite->directories() as $directory) { - $rel = self::toRelative($directory->path(), $projectRoot); + foreach (self::expandWildcards($directory->path()) as $path) { + $rel = self::toRelative($path, $projectRoot); - if ($rel !== null) { - $directories[] = $rel; + if ($rel !== null) { + $directories[] = $rel; + } } $suffixes[] = $directory->suffix(); @@ -104,6 +106,18 @@ final readonly class TestPaths return false; } + /** + * @return list + */ + private static function expandWildcards(string $path): array + { + if (! str_contains($path, '*')) { + return [$path]; + } + + return glob($path, GLOB_ONLYDIR) ?: [$path]; + } + private static function toRelative(string $value, string $projectRoot): ?string { $value = trim($value); diff --git a/tests/Features/Tia/WildcardSuiteDirectories.php b/tests/Features/Tia/WildcardSuiteDirectories.php new file mode 100644 index 00000000..b3d877c2 --- /dev/null +++ b/tests/Features/Tia/WildcardSuiteDirectories.php @@ -0,0 +1,45 @@ +seed('master'); + + $project->write('tests/Unit/BrandNewTest.php', <<<'PHP' + toBeTrue(); + }); + PHP); + + $result = $project->pest('--tia', '--filtered', ...$arguments); + + expect($result->exitCode)->toBe(0, $result->describe()) + ->and($result->output)->not->toContain('No affected tests found') + ->and($result->affected())->toBe(1, $result->describe()) + ->and($result->tally())->toContain('1 passed'); +})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows(); + +test('a test file moved under a wildcard suite directory is selected at its new path', function (array $arguments): void { + $project = Project::make('master', overlay: 'wildcard-suite'); + $project->seed('master'); + + $project->git()->run(['mv', 'tests/Unit/GreeterTest.php', 'tests/Feature/GreeterTest.php']); + + $result = $project->pest('--tia', '--filtered', ...$arguments); + + expect($result->exitCode)->toBe(0, $result->describe()) + ->and($result->output)->not->toContain('No affected tests found') + ->and($result->affected())->toBe(2, $result->describe()) + ->and($result->tally())->toContain('2 passed'); +})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows(); diff --git a/tests/Fixtures/Tia/overlays/wildcard-suite/phpunit.xml b/tests/Fixtures/Tia/overlays/wildcard-suite/phpunit.xml new file mode 100644 index 00000000..9ab17b99 --- /dev/null +++ b/tests/Fixtures/Tia/overlays/wildcard-suite/phpunit.xml @@ -0,0 +1,20 @@ + + + + + ./tests/* + + + + + ./app + + +