fix(tia): apply the prefix and suffix of source exclude directories (#2032)

This commit is contained in:
Lazizbek Ergashev
2026-11-18 20:29:39 +05:00
committed by GitHub
parent 9dc8c1d5cb
commit b4fcb2091e
4 changed files with 57 additions and 9 deletions
+13 -7
View File
@@ -35,7 +35,7 @@ final class SourceScope
/**
* @param list<string> $includes Absolute, normalised directory paths.
* @param list<string> $excludes Absolute, normalised directory paths.
* @param list<array{path: string, prefix: string, suffix: string}> $excludes Absolute, normalised directory paths with the file name prefix and suffix they apply to.
*/
public function __construct(
private readonly array $includes,
@@ -55,7 +55,11 @@ final class SourceScope
}
foreach ($source->excludeDirectories() as $dir) {
$phpunitExcludes[] = self::normalise($dir->path());
$phpunitExcludes[] = [
'path' => self::normalise(@realpath($dir->path()) ?: $dir->path()),
'prefix' => $dir->prefix(),
'suffix' => $dir->suffix(),
];
}
} catch (Throwable) {
//
@@ -64,10 +68,10 @@ final class SourceScope
$rootIncludes = self::topLevelProjectDirs($projectRoot);
$includes = array_values(array_unique([...$phpunitIncludes, ...$rootIncludes]));
$excludes = array_values(array_unique([
$excludes = [
...$phpunitExcludes,
...self::nestedNoiseDirs($projectRoot),
]));
];
if ($includes === []) {
$includes = [self::normalise($projectRoot)];
@@ -111,7 +115,9 @@ final class SourceScope
$candidate = self::normalise($candidate);
foreach ($this->excludes as $excluded) {
if ($this->startsWithDir($candidate, $excluded)) {
if ($this->startsWithDir($candidate, $excluded['path'])
&& str_starts_with(basename($candidate), $excluded['prefix'])
&& str_ends_with(basename($candidate), $excluded['suffix'])) {
return $this->containsCache[$absoluteFile] = false;
}
}
@@ -166,7 +172,7 @@ final class SourceScope
}
/**
* @return list<string>
* @return list<array{path: string, prefix: string, suffix: string}>
*/
private static function nestedNoiseDirs(string $projectRoot): array
{
@@ -174,7 +180,7 @@ final class SourceScope
foreach (self::NESTED_NOISE as $relative) {
$abs = $projectRoot.DIRECTORY_SEPARATOR.str_replace('/', DIRECTORY_SEPARATOR, $relative);
$out[] = self::normalise(@realpath($abs) ?: $abs);
$out[] = ['path' => self::normalise(@realpath($abs) ?: $abs), 'prefix' => '', 'suffix' => ''];
}
return $out;
+6 -1
View File
@@ -2061,6 +2061,11 @@
✓ it records assertions against the same per-dataset key
✓ it leaves a test without a dataset keyed by class and method
PASS Tests\Unit\Plugins\Tia\SourceScope
✓ contains() → it excludes only the files matching the suffix of an excluded directory
✓ contains() → it excludes only the files matching the prefix of an excluded directory
✓ contains() → it excludes every file of an excluded directory without a prefix or suffix
WARN Tests\Unit\Plugins\Tia\StaleCoverageLines
- a remeasured file drops line numbers that the current file no longer has → Coverage is not available
@@ -2516,4 +2521,4 @@
✓ pass with dataset with ('my-datas-set-value')
✓ within describe → pass with dataset with ('my-datas-set-value')
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1826 passed (4140 assertions)
Tests: 2 deprecated, 4 warnings, 5 incomplete, 2 notices, 40 todos, 38 skipped, 1829 passed (4146 assertions)
+37
View File
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
use Pest\Plugins\Tia\SourceScope;
describe('contains()', function (): void {
it('excludes only the files matching the suffix of an excluded directory', function (): void {
$scope = new SourceScope(
['/project/src'],
[['path' => '/project/src', 'prefix' => '', 'suffix' => 'Test.php']],
);
expect($scope->contains('/project/src/Calculator.php'))->toBeTrue()
->and($scope->contains('/project/src/CalculatorTest.php'))->toBeFalse();
});
it('excludes only the files matching the prefix of an excluded directory', function (): void {
$scope = new SourceScope(
['/project/src'],
[['path' => '/project/src', 'prefix' => 'Legacy', 'suffix' => '.php']],
);
expect($scope->contains('/project/src/Calculator.php'))->toBeTrue()
->and($scope->contains('/project/src/LegacyCalculator.php'))->toBeFalse();
});
it('excludes every file of an excluded directory without a prefix or suffix', function (): void {
$scope = new SourceScope(
['/project'],
[['path' => '/project/storage/framework', 'prefix' => '', 'suffix' => '']],
);
expect($scope->contains('/project/app/Calculator.php'))->toBeTrue()
->and($scope->contains('/project/storage/framework/views/compiled.php'))->toBeFalse();
});
});
+1 -1
View File
@@ -21,7 +21,7 @@ test('parallel', function () use ($run): void {
$output = implode("\n", array_slice(explode("\n", (string) $output), -10));
$profileOutput = $run('tests/Fixtures/Suites/SuccessOnly.php', '--profile');
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 30 skipped, 1731 passed (3744 assertions)';
$expected = '2 deprecated, 4 warnings, 5 incomplete, 3 notices, 40 todos, 30 skipped, 1734 passed (3750 assertions)';
expect($output)
->toContain("Tests: {$expected}")