fix: warns about xdebug modes

This commit is contained in:
Nuno Maduro
2021-10-10 15:25:02 +01:00
parent 04dcebf3aa
commit 1e011c7b40

View File

@ -30,14 +30,21 @@ final class Coverage
}
/**
* Runs true there is any code
* coverage driver available.
* Runs true there is any code coverage driver available.
*/
public static function isAvailable(): bool
{
return (new Runtime())->canCollectCodeCoverage();
}
/**
* If the user is using Xdebug.
*/
public static function usingXdebug(): bool
{
return (new Runtime())->hasXdebug();
}
/**
* Reports the code coverage report to the
* console and returns the result in float.
@ -45,6 +52,14 @@ final class Coverage
public static function report(OutputInterface $output): float
{
if (!file_exists($reportPath = self::getPath())) {
if (self::usingXdebug()) {
$output->writeln(
" <fg=black;bg=yellow;options=bold> WARN </> Unable to get coverage using Xdebug. Did you set Xdebug's coverage mode?</>",
);
return 0.0;
}
throw ShouldNotHappen::fromMessage(sprintf('Coverage not found in path: %s.', $reportPath));
}