Improves coverage feedback

This commit is contained in:
Nuno Maduro
2022-09-16 17:47:29 +01:00
parent 462982bb28
commit 3d5271f512
3 changed files with 34 additions and 2 deletions

View File

@ -75,7 +75,7 @@
"lint": "pint --test",
"test:lint": "pint --test",
"test:types": "phpstan analyse --ansi --memory-limit=-1 --debug",
"test:unit": "php bin/pest --colors=always --exclude-group=integration",
"test:unit": "php bin/pest --colors=always --exclude-group=integration --compact",
"test:parallel": "exit 1",
"test:integration": "php bin/pest --colors=always --group=integration -v",
"update:snapshots": "REBUILD_SNAPSHOTS=true php bin/pest --colors=always",

View File

@ -87,6 +87,24 @@ final class Coverage implements AddsOutput, HandlesArguments
$this->coverageMin = (float) $minOption;
}
if (! \Pest\Support\Coverage::isAvailable()) {
if (\Pest\Support\Coverage::usingXdebug()) {
$this->output->writeln([
'',
" <fg=default;bg=red;options=bold> ERROR </> Unable to get coverage using Xdebug. Did you set <href=https://xdebug.org/docs/code_coverage#mode>Xdebug's coverage mode</>?</>",
'',
]);
} else {
$this->output->writeln([
'',
' <fg=default;bg=red;options=bold> ERROR </> No code coverage driver is available.</>',
'',
]);
}
exit(1);
}
return $originals;
}

View File

@ -36,7 +36,21 @@ final class Coverage
*/
public static function isAvailable(): bool
{
return (new Runtime())->canCollectCodeCoverage();
$runtime = new Runtime();
if (! $runtime->canCollectCodeCoverage()) {
return false;
}
if ($runtime->hasXdebug()) {
if (version_compare((string) phpversion('xdebug'), '3.1', '>=')) {
if (! in_array('coverage', xdebug_info('mode'), true)) {
return false;
}
}
}
return true;
}
/**