From 00e7993a087a01921206d70eee153c2682e0140a Mon Sep 17 00:00:00 2001 From: Maciej Holyszko <14310995+falkenhawk@users.noreply.github.com> Date: Fri, 3 Apr 2026 09:04:37 +0200 Subject: [PATCH] skip PHP_CodeCoverage autoloading in GlobalState::phpunitFiles() phpunitFiles() builds a list of PHPUnit-internal directories to exclude from coverage reports, static attribute backup, and stack traces. It calls class_exists('PHP_CodeCoverage') which triggers autoloading on every test run, even when coverage is not in use. On php 8.4 this causes deprecation notices from PHP_CodeCoverage::__construct() due to implicit nullable parameters. Check class_exists('PHP_CodeCoverage', false) first - if coverage is not in use, the class won't be loaded and its directory doesn't need to be excluded from anything. This avoids the need to fork phpunit/php-code-coverage just to silence a deprecation notice. --- PHPUnit/Util/GlobalState.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/PHPUnit/Util/GlobalState.php b/PHPUnit/Util/GlobalState.php index be18c7ad0b..c0021de03e 100644 --- a/PHPUnit/Util/GlobalState.php +++ b/PHPUnit/Util/GlobalState.php @@ -404,7 +404,20 @@ public static function phpunitFiles() if (self::$phpunitFiles === NULL) { self::$phpunitFiles = array(); self::addDirectoryContainingClassToPHPUnitFilesList('File_Iterator'); - self::addDirectoryContainingClassToPHPUnitFilesList('PHP_CodeCoverage'); + // phpunitFiles() collects directories of PHPUnit's internal packages + // to exclude them from stack traces and from the list of included files + // when running tests in separate processes. + // + // When code coverage is enabled, TestRunner loads PHP_CodeCoverage + // before any tests run, so class_exists() returns true here. + // When coverage is off, the class is not loaded and its directory + // does not need to be excluded from anything. + // + // Check without autoloading (false) to avoid triggering implicit + // nullable deprecation from php-code-coverage on php 8.4. + if (class_exists('PHP_CodeCoverage', false)) { + self::addDirectoryContainingClassToPHPUnitFilesList('PHP_CodeCoverage'); + } self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Invoker'); self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Timer'); self::addDirectoryContainingClassToPHPUnitFilesList('PHP_Token');