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 + + +