From 0a7f0acf9269c190fd982b5c04423feae986b6e0 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Fri, 27 Nov 2020 07:15:15 +0100 Subject: [PATCH] Closes #834 --- ChangeLog.md | 7 +++++++ src/Driver/Xdebug3Driver.php | 11 ++++++++++- src/Exception/Xdebug2NotEnabledException.php | 2 +- src/Exception/Xdebug3NotEnabledException.php | 2 +- src/Version.php | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 80ffd8bcf..6a60f5c35 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -2,6 +2,12 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [9.2.4] - 2020-11-27 + +### Added + +* [#834](https://github.com/sebastianbergmann/php-code-coverage/issues/834): Support `XDEBUG_MODE` environment variable + ## [9.2.3] - 2020-10-30 ### Changed @@ -306,6 +312,7 @@ All notable changes are documented in this file using the [Keep a CHANGELOG](htt * Class names are now abbreviated (unqualified name shown, fully qualified name shown on hover) in the file view of the HTML report * Update HTML report to Bootstrap 4 +[9.2.4]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.3...9.2.4 [9.2.3]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.2...9.2.3 [9.2.2]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.1...9.2.2 [9.2.1]: https://github.com/sebastianbergmann/php-code-coverage/compare/9.2.0...9.2.1 diff --git a/src/Driver/Xdebug3Driver.php b/src/Driver/Xdebug3Driver.php index ddae81511..b85bfab0e 100644 --- a/src/Driver/Xdebug3Driver.php +++ b/src/Driver/Xdebug3Driver.php @@ -14,7 +14,9 @@ use const XDEBUG_CC_UNUSED; use const XDEBUG_FILTER_CODE_COVERAGE; use const XDEBUG_PATH_INCLUDE; +use function explode; use function extension_loaded; +use function getenv; use function in_array; use function ini_get; use function phpversion; @@ -52,7 +54,14 @@ public function __construct(Filter $filter) ); } - if (!ini_get('xdebug.mode') || !in_array('coverage', explode(',', ini_get('xdebug.mode')), true)) { + $mode = getenv('XDEBUG_MODE'); + + if ($mode === false) { + $mode = ini_get('xdebug.mode'); + } + + if ($mode === false || + !in_array('coverage', explode(',', $mode), true)) { throw new Xdebug3NotEnabledException; } diff --git a/src/Exception/Xdebug2NotEnabledException.php b/src/Exception/Xdebug2NotEnabledException.php index 914c3d170..3039e77c0 100644 --- a/src/Exception/Xdebug2NotEnabledException.php +++ b/src/Exception/Xdebug2NotEnabledException.php @@ -16,6 +16,6 @@ final class Xdebug2NotEnabledException extends RuntimeException implements Excep { public function __construct() { - parent::__construct('xdebug.coverage_enable=On has to be set in php.ini'); + parent::__construct('xdebug.coverage_enable=On has to be set'); } } diff --git a/src/Exception/Xdebug3NotEnabledException.php b/src/Exception/Xdebug3NotEnabledException.php index b21567a90..5d3b106ce 100644 --- a/src/Exception/Xdebug3NotEnabledException.php +++ b/src/Exception/Xdebug3NotEnabledException.php @@ -16,6 +16,6 @@ final class Xdebug3NotEnabledException extends RuntimeException implements Excep { public function __construct() { - parent::__construct('xdebug.mode=coverage has to be set in php.ini'); + parent::__construct('XDEBUG_MODE=coverage or xdebug.mode=coverage has to be set'); } } diff --git a/src/Version.php b/src/Version.php index 018460c1d..578fdc67f 100644 --- a/src/Version.php +++ b/src/Version.php @@ -22,7 +22,7 @@ final class Version public static function id(): string { if (self::$version === null) { - self::$version = (new VersionId('9.2.3', dirname(__DIR__)))->getVersion(); + self::$version = (new VersionId('9.2.4', dirname(__DIR__)))->getVersion(); } return self::$version;