diff --git a/src/Actions/MapArguments.php b/src/Actions/MapArguments.php index 16b1e0f7..57127325 100644 --- a/src/Actions/MapArguments.php +++ b/src/Actions/MapArguments.php @@ -17,8 +17,8 @@ final class MapArguments { public static function toParatest(TestSuite $testSuite): void { - self::coverage(); self::registerPlugins(); + self::coverage(); self::parallel(); self::color(); } @@ -26,6 +26,7 @@ final class MapArguments public static function toPest(TestSuite $testSuite): void { self::inParallel($testSuite); + // we could add coverage here too, so we stop before even running tests if there is no coverage driver } private static function registerPlugins(): void @@ -70,7 +71,7 @@ final class MapArguments private static function coverage(): void { - if (! Coverage::isAvailable()) { + if (self::needsCoverage() && ! Coverage::isAvailable()) { Container::getInstance()->get(OutputInterface::class)->writeln( "\n ERROR No code coverage driver is available.", ); @@ -78,6 +79,17 @@ final class MapArguments } } + private static function needsCoverage(): bool + { + foreach ($_SERVER['argv'] as $argument) { + if(str_starts_with($argument, '--coverage')) { + return true; + } + } + + return false; + } + private static function unsetArgument(string $argument): bool { if (($key = array_search($argument, $_SERVER['argv'])) !== false) {