fix(tia): record new dependencies of known tests on coverage runs (#1955)

* fix(tia): record new dependencies of known tests on coverage runs

* chore(tia): drop the keepExisting docblock line
This commit is contained in:
Lazizbek Ergashev
2026-10-31 19:47:06 +05:00
committed by GitHub
parent 85d24777b5
commit 228c627b64
2 changed files with 33 additions and 6 deletions
+1 -6
View File
@@ -1025,7 +1025,6 @@ final class Graph
/**
* @param array<string, array<int, string>> $testToFiles
* @param bool $keepExisting Leave already-recorded edge sets alone.
*/
public function replaceEdges(array $testToFiles, bool $keepExisting = false): void
{
@@ -1036,11 +1035,7 @@ final class Graph
continue;
}
if ($keepExisting && ($this->edges[$testRel] ?? []) !== []) {
continue;
}
$this->edges[$testRel] = [];
$this->edges[$testRel] = $keepExisting ? ($this->edges[$testRel] ?? []) : [];
foreach ($sources as $source) {
$this->link($testFile, $source);
+32
View File
@@ -90,3 +90,35 @@ test('a coverage report leaves the edges of an existing graph alone', function (
->and($delta->removed())->toBe(0, $delta->summary())
->and($delta->added())->toBe(0, $delta->summary());
})->skipOnWindows();
test('a coverage report adds a new dependency to the edges of an existing graph', function (array $arguments): void {
$project = Project::make('master');
$project->seed('master');
$project->write('app/Greeter.php', <<<'PHP'
<?php
declare(strict_types=1);
namespace Fixture\App;
final class Greeter
{
public function greet(string $name): string
{
(new Calculator)->add(1, 1);
return sprintf('Hello, %s!', $name);
}
}
PHP);
$result = $project->pest('--tia', '--coverage', ...$arguments);
$graph = $project->graph();
$edges = array_map(fn (int $id): string => $graph['files'][$id], $graph['edges']['tests/Unit/GreeterTest.php']);
expect($result->exitCode)->toBe(0, $result->describe())
->and($edges)->toContain('app/Greeter.php')
->and($edges)->toContain('app/Calculator.php');
})->with(Project::SEQUENTIAL_AND_PARALLEL)->skipOnWindows()->skip(! Coverage::isAvailable(), 'Coverage is not available');