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

Code coverage filter configuration is not passed to child processes #1681

Closed
davedevelopment opened this issue Apr 16, 2015 · 4 comments
Closed

Comments

@davedevelopment
Copy link

Code coverage simply gets enabled for tests that run in child processes, configuration is not carried forward. The code coverage library doesn't filter data that is merged in, so whitelists and blacklists are not respected when tests are run in a separate process.

Related sebastianbergmann/php-code-coverage#327

<?xml version="1.0" encoding="UTF-8"?>

<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
    backupGlobals               = "false"
    backupStaticAttributes      = "false"
    colors                      = "true"
    convertErrorsToExceptions   = "true"
    convertNoticesToExceptions  = "true"
    convertWarningsToExceptions = "true"
    processIsolation            = "false"
    stopOnFailure               = "false"
    syntaxCheck                 = "false"
    bootstrap                   = "vendor/autoload.php" >

    <testsuites>
        <testsuite name="Project Test Suite">
            <file>AllTest.php</file>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <file>Whitelisted.php</file>
        </whitelist>
    </filter>

</phpunit>
<?php

class AllTest extends \PHPUnit_Framework_TestCase
{
    /** @test */
    public function will_have_correct_code_coverage_info()
    {
        $a = new Whitelisted();
        $b = new NotWhitelisted();
    }

    /**
     * @test
     * @runInSeparateProcess
     */
    public function will_report_coverage_for_vendor_files()
    {
        $a = new Whitelisted();
        $b = new NotWhitelisted();
    }
}
davem@wes:phpunit-coverage-test$ php -v
PHP 5.6.0 (cli) (built: Oct  4 2014 20:38:24)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies
    with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
davem@wes:phpunit-coverage-test$ phpunit --coverage-text
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /home/davem/phpunit-coverage-test/phpunit.xml.dist

..

Time: 654 ms, Memory: 6.00Mb

OK (2 tests, 0 assertions)


Code Coverage Report:
  2015-04-16 09:34:15

 Summary:
  Classes: 25.00% (2/8)
  Methods:  3.77% (2/53)
  Lines:    0.23% (4/1735)

NotWhitelisted
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  2/  2)
Whitelisted
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  2/  2)

I would expect to not see coverage data for NotWhitelisted.php. Avoiding the test that runs in a child process correctly filters the coverage data:

davem@wes:phpunit-coverage-test$ phpunit --coverage-text --filter will_have_correct_code_coverage_info
PHPUnit 4.6.4 by Sebastian Bergmann and contributors.

Configuration read from /home/davem/phpunit-coverage-test/phpunit.xml.dist

.

Time: 90 ms, Memory: 6.00Mb

OK (1 test, 0 assertions)


Code Coverage Report:
  2015-04-16 09:34:23

 Summary:
  Classes: 100.00% (1/1)
  Methods: 100.00% (1/1)
  Lines:   100.00% (2/2)

Whitelisted
  Methods: 100.00% ( 1/ 1)   Lines: 100.00% (  2/  2)
davem@wes:phpunit-coverage-test$
@OndraM
Copy link
Contributor

OndraM commented May 29, 2015

👍 Also affected, PHPUnit 4.6.6

@sebastianbergmann
Copy link
Owner

Can you please test whether dc8726a solves your problem?

@OndraM
Copy link
Contributor

OndraM commented May 29, 2015

Hi, it fixed the original problem (now the coverage whitelist defined in phpunit.xml is respected even for tests run in separate process), however, the coverage counting is now broken:

The original coverage witih PHPUnit 4.6.9:
coverage-469

Coverage with the dc8726a:
coverage-version

Note few files are not included in the new report (866 instead of 889), which is proper behavior, however, the percentage is miscalculated. It looks like only the classes tested in separate process were counted.

@sebastianbergmann
Copy link
Owner

I have merged dc8726a into 4.7 and am closing this issue. If there is a problem with the actual merging of code coverage data then please open a ticket at https://github.com/sebastianbergmann/php-code-coverage/issues/new.

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

3 participants