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

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

Closed
thirsch opened this issue Nov 23, 2020 · 0 comments
Closed

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

thirsch opened this issue Nov 23, 2020 · 0 comments

Comments

@thirsch
Copy link
Contributor

thirsch commented Nov 23, 2020

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.

@sebastianbergmann sebastianbergmann changed the title Empty php files cause coverage to fail. Files that do not contain a newline are not handled correctly Nov 28, 2020
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

1 participant