Skip to content
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

PHP report does not handle serialized code coverage data larger than 2 GB #971

Closed
sakarikl opened this issue Dec 22, 2022 · 3 comments
Closed

Comments

@sakarikl
Copy link

Q A
php-code-coverage version 9.2.22
PHP version 8.1.13
Driver PCOV
PCOV version (if used) 1.0.11
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 9.5.27

Generating code coverage report in PHP format ... PHP Fatal error: Field width 2251485604 is too long in /.../vendor/phpunit/php-code-coverage/src/Report/PHP.php on line 30
Fatal error: Field width 2251485604 is too long in /.../vendor/phpunit/php-code-coverage/src/Report/PHP.php on line 30

triggered with command:

php -dpcov.enabled=1 -dpcov.directory=${CI_PROJECT_DIR} -dmemory_limit=10G -dmax_execution_time=3600 ../vendor/bin/phpunit -c phpunit.coverage.xml --coverage-php=${CI_PROJECT_DIR}/reports/coverage-report.php --log-junit ../reports/func-junit.xml functional 

this is our codebase size:

phploc 7.0.2 by Sebastian Bergmann.

Directories                                       1873
Files                                             7505

Size
  Lines of Code (LOC)                          1108084
  Comment Lines of Code (CLOC)                  214571 (19.36%)
  Non-Comment Lines of Code (NCLOC)             893513 (80.64%)
  Logical Lines of Code (LLOC)                  273299 (24.66%)
    Classes                                     265136 (97.01%)

And size of tests:

phploc 7.0.2 by Sebastian Bergmann.

Directories                                       1048
Files                                             2345

Size
  Lines of Code (LOC)                           253418
  Comment Lines of Code (CLOC)                   16828 (6.64%)
  Non-Comment Lines of Code (NCLOC)             236590 (93.36%)
  Logical Lines of Code (LLOC)                   78561 (31.00%)
    Classes                                      78558 (100.00%)

@sebastianbergmann
Copy link
Owner

Does this help?

diff --git a/src/Report/PHP.php b/src/Report/PHP.php
index d16b1b8..d45136c 100644
--- a/src/Report/PHP.php
+++ b/src/Report/PHP.php
@@ -21,14 +21,8 @@ final class PHP
 {
     public function process(CodeCoverage $coverage, ?string $target = null): string
     {
-        $buffer = sprintf(
-            "<?php
-return \unserialize(<<<'END_OF_COVERAGE_SERIALIZATION'%s%s%sEND_OF_COVERAGE_SERIALIZATION%s);",
-            PHP_EOL,
-            serialize($coverage),
-            PHP_EOL,
-            PHP_EOL
-        );
+        $buffer = "<?php
+return \unserialize(<<<'END_OF_COVERAGE_SERIALIZATION'" . PHP_EOL . serialize($coverage) . PHP_EOL . "END_OF_COVERAGE_SERIALIZATION" . PHP_EOL . ");";
 
         if ($target !== null) {
             Filesystem::createDirectory(dirname($target));

@sebastianbergmann sebastianbergmann changed the title php-code-coverage/src/Report/PHP.php on line 30 sprintf receives string longer than 2G PHP report does not handle serialized code coverage data larger than 2 GB Dec 22, 2022
@sakarikl
Copy link
Author

With that patch the process was successful.

Generating code coverage report in PHP format ... done [00:07.920]

Thank you for your really quick response.

Would that $buffer variable still might cause the same problem in the future?

@sebastianbergmann
Copy link
Owner

Would that $buffer variable still might cause the same problem in the future?

It's not about the $buffer variable itself, but about the sprintf() function.

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

No branches or pull requests

2 participants