From 1e011c7b4074d08f5dabab1f927d45383c85d210 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Sun, 10 Oct 2021 15:25:02 +0100 Subject: [PATCH] fix: warns about xdebug modes --- src/Support/Coverage.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Support/Coverage.php b/src/Support/Coverage.php index 4d2096c9..61b7bee6 100644 --- a/src/Support/Coverage.php +++ b/src/Support/Coverage.php @@ -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( + " 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)); }