fix(tia): match test files under wildcard suite directories (#1980)

Co-authored-by: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com>
This commit is contained in:
Mozex
2026-11-03 18:08:16 +03:00
committed by GitHub
parent 09a36c97f3
commit e5906a50cf
3 changed files with 82 additions and 3 deletions
+17 -3
View File
@@ -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<string>
*/
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);
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
use Tests\Fixtures\Tia\Project;
afterEach(function (): void {
Project::destroyAll();
});
test('a new test file under a wildcard suite directory is selected', function (array $arguments): void {
$project = Project::make('master', overlay: 'wildcard-suite');
$project->seed('master');
$project->write('tests/Unit/BrandNewTest.php', <<<'PHP'
<?php
declare(strict_types=1);
test('brand new thing', function (): void {
expect(true)->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();
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
failOnRisky="true"
failOnWarning="false"
>
<testsuites>
<testsuite name="default">
<directory suffix="Test.php">./tests/*</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./app</directory>
</include>
</source>
</phpunit>