-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Code Coverage data serialized from PHPUnit PHAR cannot be processed by PHPCOV #109
Comments
Hi all. Thanks Michael to have reported this and give me the direction for solving my problem. |
@sebastianbergmann I have just ran into this same issue. Using phpunit from direct wget download: Then use phpunit to generate a few .cov files for a few different unit tests. If I use the phpunit from composer to run tests and generate .cov files, it works as expected as others here have commented. I'm pretty sure I have figured out the reason why. Here is my analysis: The declared namespace is: When I view the same file from the composer install: The declared namespace is: Note the missing PHPUnit prefix. I've also extracted the phpcov.phar. When I view the same file again: The declared namespace is: Also missing the PHPUnit prefix. So, when the phpcov utility tries to unserialize the CodeCoverage object (MergeComand.php line 57), it does an instanceof check:
When using the phpunit.phar from wget to generate .cov files of CodeCoverage objects, they are serialized down with a different fully qualified class name than when using the composer tools. Since the fully qualified class names aren't the same, the check fails and an error is raised. |
Thank you, @twoseascharlie, that makes sense. We need to either "rewrite" the serialized object representation before we call |
My .cov files had the
But the CodeCoverage classes are under a different namespace. I've used the script below to convert the files: <?php
$content = file_get_contents($_SERVER['argv'][1]);
echo preg_replace_callback("#\:(\d+)\:\"(.?)PHPUnit\\\SebastianBergmann\\\#", function($matches) {
$hasNull = strlen($matches[2]) === 1;
$size = $matches[1];
$size -= 8;
if ($hasNull) {
return sprintf(":%d:\"\0SebastianBergmann\\", $size);
}
return sprintf(':%d:"SebastianBergmann\\', $size);
}, $content); I managed to merge a couple of .cov files together after this. I've closed phpcov + composer install to run it, have not tried with the PHAR. It's a workaround nonetheless, I wouldn't add this to my CI/CD pipeline. Use at your own risk. |
FWIW, it still happens with <!-- .phive/phars.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpunit" version="^9.5.20" installed="9.5.20" location="./tools/phpunit.phar" copy="true"/>
<phar name="phpcov" version="^8.2.1" installed="8.2.1" location="./tools/phpcov.phar" copy="true"/>
</phive> |
@sebastianbergmann do you know of any way to circumvent this behaviour? Even after applying the workaround provided by kassner, phpcov throws the following error message:
FTR: I'm testing this with phpunit.phar v9.6.8 and phpcov.phar v9.0.0 |
@kassner's great workaround from above in a single line (Perl, though 😉):
|
Do I understand the current situation correctly? If that is the case, then a short-term solution could be to introduce PHP-Scoper into the build process of PHPCOV's PHAR. Then data generated using PHPUnit's PHAR should be processable by PHPCOV's PHAR. We could also look into using I hope to find the time it takes to "dust off" PHPCOV and fix all current issues soon. |
Hi @NicoHaase, I have same the problem like you. I think the problem is, that your generated cov files by PHPUnit are incompatible to your phpcov version. In my case, PHPUnit 9.5.24 are not compatible with phpcov >= 9. The readme says
I think using composer is the only way to use the correct version of pcov + phpunit, because there are no indication which versions are compatible to each other, beside git history and composer.json. My workaround for PHPUnit 9.5 and PHP 8.2: composer require "phpunit/phpcov:*"
php '-derror_reporting=E_ALL & ~E_DEPRECATED' vendor/phpunit/phpcov/phpcov merge |
This reverts commit 2654af9. Didn't seem to work - issue similar to sebastianbergmann/phpcov#109
Summary
When using PHPUnit phar archive (installed via phive), the generated php coverage report cannot be processed by phpcov 8.2.0 (also PHAR installed via phive). When using the same PHPUnit version installed via composer, phpcov processes the report.
Current behavior
Result:
When doing the same using a PHPunit installed via composer, everything works just fine:
How to reproduce
Use the minimal example attached. The testreport directory also contains the output files that both the PHAR version as well as the composer version produced.
Expected behavior
PHAR version should work the same as the version from composer.
The text was updated successfully, but these errors were encountered: