Skip to content

Files that do not contain a newline are not handled correctly #831

@thirsch

Description

@thirsch
Q A
php-code-coverage version 9.2.3
PHP version 7.4.12
Driver Xdebug
Xdebug version (if used) 2.9.8
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 9.4.3

If there is an completely empty file with only one line without a trailing linebreak in your coverage folder, the coverage can't be created, because the value for $linesOfCode after counting \n is 0, whereas the calculated amount of comments is 1 and results in an exception of type SebastianBergmann\LinesOfCode\NegativeValueException.

Fatal error: Uncaught SebastianBergmann\LinesOfCode\NegativeValueException: $nonCommentLinesOfCode must not be negative in /.../vendor/phpunit/phpunit/src/TextUI/Command.php on line 103

PHPUnit\TextUI\Exception: $nonCommentLinesOfCode must not be negative in /.../vendor/phpunit/phpunit/src/TextUI/Command.php on line 103

Call Stack:
    0.0006     411104   1. {main}() /.../vendor/phpunit/phpunit/phpunit:0
    0.0162    1110472   2. PHPUnit\TextUI\Command::main() /var/ftproot/www/symfony-tests/vendor/phpunit/phpunit/phpunit:61

We've had no issues with PHPUnit 8.* and below with empty files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions