Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion plugin/codecov/src/Internal/Driver/PcovDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@

\pcov\clear();

return CoverageResult::fromRawData($data);
return CoverageResult::fromRawData(PseudoFile::remove($data));

Check warning on line 82 in plugin/codecov/src/Internal/Driver/PcovDriver.php

View check run for this annotation

Codecov / codecov/patch

plugin/codecov/src/Internal/Driver/PcovDriver.php#L82

Added line #L82 was not covered by tests
}

#[\Override]
Expand Down
62 changes: 62 additions & 0 deletions plugin/codecov/src/Internal/Driver/PseudoFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

declare(strict_types=1);

namespace Testo\Codecov\Internal\Driver;

use Testo\Inline\TestInline;

/**
* Recognizes the names coverage engines give to code without a file of its own: `eval()`'d code,
* runtime-created functions, assertion strings, standard input.
*
* Such a name starts with the path of the file that produced the code, so a path-prefix filter alone lets it through.
*
* @internal
*/
final class PseudoFile
{
private const MARKERS = [
'xdebug://debug-eval',
"eval()'d code",
'runtime-created function',
'runkit created function',
'assert code',
'regexp code',
'Standard input code',
];

#[TestInline(["/app/src/Foo.php(64) : eval()'d code"], result: true)]
#[TestInline(["C:\\app\\src\\Foo.php(3) : eval()'d code"], result: true)]
#[TestInline(['xdebug://debug-eval'], result: true)]
#[TestInline(['/app/src/Foo.php(10) : runtime-created function'], result: true)]
#[TestInline(['Standard input code'], result: true)]
#[TestInline(['-'], result: true)]
#[TestInline(['vfs://root/Foo.php'], result: true)]
#[TestInline(['/app/src/Foo.php'], result: false)]
#[TestInline(['C:\\app\\src\\Foo.php'], result: false)]
public static function is(string $path): bool
{
if ($path === '-' || \str_starts_with($path, 'vfs://')) {
return true;
}

foreach (self::MARKERS as $marker) {
if (\str_contains($path, $marker)) {
return true;
}
}

return false;
}

/**
* @template T
* @param array<string, T> $data Raw coverage keyed by file path.
* @return array<string, T>
*/
public static function remove(array $data): array
{
return \array_filter($data, static fn(string $path): bool => !self::is($path), \ARRAY_FILTER_USE_KEY);

Check warning on line 60 in plugin/codecov/src/Internal/Driver/PseudoFile.php

View check run for this annotation

Codecov / codecov/patch

plugin/codecov/src/Internal/Driver/PseudoFile.php#L60

Added line #L60 was not covered by tests
}
}
2 changes: 1 addition & 1 deletion plugin/codecov/src/Internal/Driver/XdebugDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
}
}

return CoverageResult::fromRawData($data);
return CoverageResult::fromRawData(PseudoFile::remove($data));

Check warning on line 109 in plugin/codecov/src/Internal/Driver/XdebugDriver.php

View check run for this annotation

Codecov / codecov/patch

plugin/codecov/src/Internal/Driver/XdebugDriver.php#L109

Added line #L109 was not covered by tests
}

#[\Override]
Expand Down
Loading