mirror of
https://github.com/pestphp/pest.git
synced 2026-12-04 06:55:05 +01:00
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:
committed by
GitHub
parent
85d24777b5
commit
228c627b64
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user