Skip to content

Commit

Permalink
fix(uncovered-scenarios): tries to find related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro committed Sep 29, 2024
1 parent d20128d commit 3da57e7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/MutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ public function updateResult(MutationTestResult $result): void
public function start(array $coveredLines, Configuration $configuration, array $originalArguments, ?int $processId = null): bool
{
// TODO: we should pass the tests to run in another way, maybe via cache, mutation or env variable

$filters = [];
foreach (range($this->mutation->startLine, $this->mutation->endLine) as $lineNumber) {
foreach ($coveredLines[$this->mutation->file->getRealPath()][$lineNumber] ?? [] as $test) {
$tests = $coveredLines[$this->mutation->file->getRealPath()][$lineNumber] ?? [];

if ($tests === [] && array_key_exists($this->mutation->file->getRealPath(), $coveredLines)) {
$tests = array_unique(array_merge(...array_values($coveredLines[$this->mutation->file->getRealPath()])));
}

foreach ($tests as $test) {
preg_match('/\\\\([a-zA-Z0-9]*)::(__pest_evaluable_)?([^#]*)"?/', $test, $matches);
if ($matches[2] === '__pest_evaluable_') { // @phpstan-ignore-line
$filters[] = $matches[1].'::(.*)'.str_replace(['__', '_'], ['.{1,2}', '.'], $matches[3]); // @phpstan-ignore-line
Expand All @@ -59,6 +66,7 @@ public function start(array $coveredLines, Configuration $configuration, array $
}
}
}

$filters = array_unique($filters);

if ($filters === []) {
Expand Down

0 comments on commit 3da57e7

Please sign in to comment.