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

Incorrect code coverage when process isolation is used #4283

Closed
dac514 opened this issue Jun 10, 2020 · 6 comments
Closed

Incorrect code coverage when process isolation is used #4283

dac514 opened this issue Jun 10, 2020 · 6 comments
Labels
feature/code-coverage Issues related to code coverage (but not php-code-coverage) feature/process-isolation Issues related to running tests in separate PHP processes type/bug Something is broken

Comments

@dac514
Copy link

dac514 commented Jun 10, 2020

Q A
PHPUnit version 8.5.5
PHP version 7.3.17
Installation Method Composer

Reported to pcov, answer was "This is an upstream problem: phpunit is failing to set the interpreter for the new process with the configuration from the parent process.":

See: krakjoe/pcov#51

Summary

The problem is, depending on how phpunit.xml is configured, I get two different coverage reports for the same file, one of which is less accurate. See screenshots:

Screen Shot 2020-06-09 at 1 56 09 PM
Screen Shot 2020-06-09 at 1 56 51 PM

Current behavior

Poor code coverage report about the switch statement.

How to reproduce

  1. Download attached code: pcov-bug-report.zip
  2. composer install
  3. ./vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml

Zip file contains:

.
├── clover-processIsolation-false.xml
├── clover-processIsolation-true.xml
├── composer.json
├── composer.lock
├── src
│   ├── One
│   │   ├── SupportedCountriesISO2.php
│   │   └── SupportedCountriesISO3.php
│   └── Two
│       └── Example.php
└── tests
    ├── Unit
    │   └── ExampleTest.php
    └── phpunit.xml

Expected behavior

More accurate code coverage reports about the switch statement.

Workarounds

  1. If I open tests/phpunit.xml and change processIsolation="false" to processIsolation="true" the coverage is more accurate.

  2. Or, if I open tests/phpunit.xml and change: processUncoveredFilesFromWhitelist="true"
    to processUncoveredFilesFromWhitelist="false" the coverage is more accurate.

Unfortunately, these workarounds improve this specific case, but worsen the overall metrics in my real project so I cannot use them.

@dac514 dac514 added the type/bug Something is broken label Jun 10, 2020
@sebastianbergmann sebastianbergmann added feature/code-coverage Issues related to code coverage (but not php-code-coverage) feature/process-isolation Issues related to running tests in separate PHP processes labels Jun 10, 2020
@sebastianbergmann sebastianbergmann changed the title Missing Code Coverage When Phpunit's Process Isolation Is False (pcov) Incorrect code coverage when process isolation is used Dec 28, 2020
@yeroon
Copy link

yeroon commented Mar 10, 2022

Same problem here with php 7.4.3, phpunit 8.5.24. using pcov

@JoaoDias-223
Copy link

Same problem here with php 7.1.33 and PHPUnit 7.5.20 using XDebug

@sebastianbergmann
Copy link
Owner

Same problem here with php 7.1.33 and PHPUnit 7.5.20 using XDebug

PHPUnit 7.5 is no longer maintained, neither is PHP 7.1.

@mxsxs2
Copy link

mxsxs2 commented Feb 17, 2023

I think I encountered this same issue with version 10.0.7 of phpunit.
When I use --process-isolation I get 0.0% coverage. This used to work in phpunit 9.x

How to reproduce:

  1. Create a new Laravel project with composer
    composer create-project laravel/laravel example-app
  2. Run XDEBUG_MODE=coverage ./vendor/phpunit/phpunit/phpunit --coverage-text --process-isolation

Outcome:
image

Expected:
image

Both tests were run on the out of the box Laravel project. The only difference is the use of --process-isolation flag.

I tried with two separate PHP setups:

PHP 8.1.2 (cli) (built: Apr 7 2022 17:46:26) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies
with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans

PHP 8.2.3 (cli) (built: Feb 14 2023 20:52:32) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.3, Copyright (c) Zend Technologies
with Zend OPcache v8.2.3, Copyright (c), by Zend Technologies
with Xdebug v3.2.0, Copyright (c) 2002-2022, by Derick Rethans

It would be nice to have process isolation working again as I have over 300 tests and my containers get killed with OOM during tests.

@sebastianbergmann If you'd like I can open this as a new issue, given that this issue is almost a year old and originally reported for different environment.

@sebastianbergmann
Copy link
Owner

If you'd like I can open this as a new issue, given that this issue is almost a year old and originally reported for different environment.

Yes, please. Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting. And please compare PHPUnit 10 without process isolation versus PHPUnit 10 with process isolation, not PHPUnit 9 versus PHPUnit 10.

@mxsxs2
Copy link

mxsxs2 commented Feb 20, 2023

@sebastianbergmann My issue was the same as #5218 and resolved by #5221

Thanks for looking into it and get it resolved!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/code-coverage Issues related to code coverage (but not php-code-coverage) feature/process-isolation Issues related to running tests in separate PHP processes type/bug Something is broken
Projects
None yet
Development

No branches or pull requests

5 participants