Skip to content

prevent PHP_CodeCoverage autoloading when coverage is not enabled to avoid deprecation notice on php 8.4+#26

Merged
falkenhawk merged 1 commit intomasterfrom
fix-codecoverage-autoload
Apr 3, 2026
Merged

prevent PHP_CodeCoverage autoloading when coverage is not enabled to avoid deprecation notice on php 8.4+#26
falkenhawk merged 1 commit intomasterfrom
fix-codecoverage-autoload

Conversation

@falkenhawk
Copy link
Copy Markdown
Member

@falkenhawk falkenhawk commented Apr 3, 2026

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 from PHP_CodeCoverage::__construct() due to implicit nullable parameters in phpunit/php-code-coverage.

When code coverage is enabled, TestRunner loads PHP_CodeCoverage before any tests run, so class_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 by TestRunner.

@falkenhawk falkenhawk force-pushed the fix-codecoverage-autoload branch 2 times, most recently from 530d29d to 62f7f33 Compare April 3, 2026 07:17
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.
@falkenhawk falkenhawk force-pushed the fix-codecoverage-autoload branch from 62f7f33 to 00e7993 Compare April 3, 2026 07:18
@falkenhawk falkenhawk changed the title prevent PHP_CodeCoverage autoloading on php 8.4+ prevent PHP_CodeCoverage autoloading on php 8.4+ when coverage is not enabled Apr 3, 2026
@falkenhawk falkenhawk changed the title prevent PHP_CodeCoverage autoloading on php 8.4+ when coverage is not enabled prevent PHP_CodeCoverage autoloading when coverage is not enabled Apr 3, 2026
@falkenhawk falkenhawk changed the title prevent PHP_CodeCoverage autoloading when coverage is not enabled prevent PHP_CodeCoverage autoloading when coverage is not enabled to avoid deprecation notice on php 8.4+ Apr 3, 2026
@falkenhawk falkenhawk merged commit 3f77482 into master Apr 3, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant