-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Coverage information (wrongly?) affected by opcache #101
Comments
I can reproduce this:
Disabling just OpCache's optimizer works around the issue just as disabling OpCache entirely does. |
We cannot reproduce this with Xdebug. According to @derickr, this is because "Xdebug sets the The patch shown below fixes the problem for me: diff --git a/pcov.c b/pcov.c
index f04ba9c..c354f72 100644
--- a/pcov.c
+++ b/pcov.c
@@ -441,6 +441,8 @@ PHP_RINIT_FUNCTION(pcov)
CG(compiler_options) |= ZEND_COMPILE_NO_JUMPTABLES;
#endif
+ CG(compiler_options) |= ZEND_COMPILE_EXTENDED_STMT;
+
if (!zend_compile_file_function) {
zend_compile_file_function = zend_compile_file;
zend_compile_file = php_pcov_compile_file; |
The patch looks sensible to me. However, tests/gh101.phpt--TEST--
GH-101 (Coverage information affected by opcache)
--SKIPIF--
<?php if (!extension_loaded("pcov")) print "skip"; ?>
--INI--
pcov.enabled = 1
--FILE--
<?php
function test(array $data) {
$result = [];
foreach($data as $value) {
if (!isOkay($value)) {
continue;
}
$result[] = $value;
}
return $result;
}
function isOkay(string $input): bool {
return $input !== 'b';
}
\pcov\start();
test(["a", "b", "c"]);
\pcov\stop();
var_dump(\pcov\collect());
?>
--EXPECTF--
array(1) {
["%s%egh101.php"]=>
array(12) {
[16]=>
int(-1)
[17]=>
int(1)
[18]=>
int(1)
[20]=>
int(-1)
[22]=>
int(-1)
[3]=>
int(1)
[4]=>
int(1)
[5]=>
int(1)
[6]=>
int(1)
[8]=>
int(1)
[10]=>
int(1)
[14]=>
int(1)
}
} |
It appears that code coverage information changes whether or not opcache is enabled. That's at least true for a line containing
continue
in the reproducer sample code.I created a selfcontained repo here: https://github.com/theseer/infection-bug.
(It's named infection bug because i originally believed that to be an issue with infection)
Having PHP 8.2.8 / PCOV 1.0.11 with all the other extension loaded that phpunit requires + opcache on Fedora 38 x86_64.
The reproducer uses PHPUnit 10.2.6
With opcache effectively disabled:
With opcache enabled, also for CLI:
I believe this to be wrong.
The text was updated successfully, but these errors were encountered: