prevent PHP_CodeCoverage autoloading when coverage is not enabled to avoid deprecation notice on php 8.4+#26
Merged
falkenhawk merged 1 commit intomasterfrom Apr 3, 2026
Conversation
530d29d to
62f7f33
Compare
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.
62f7f33 to
00e7993
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GlobalState::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.It calls
class_exists('PHP_CodeCoverage')which triggers autoloading of the class on every test run, even when coverage is not in use. On php 8.4 this causes deprecation notices fromPHP_CodeCoverage::__construct()due to implicit nullable parameters inphpunit/php-code-coverage.When code coverage is enabled,
TestRunnerloadsPHP_CodeCoveragebefore any tests run, soclass_exists()would return true regardless. When coverage is off, the class is not loaded and its directory does not need to be excluded from anything.The fix checks
class_exists('PHP_CodeCoverage', false)- skipping autoloading and only checking if the class was already loaded byTestRunner.