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

Lines not covered when more tests are run #17

Closed
kubawerlos opened this issue Jun 2, 2019 · 17 comments
Closed

Lines not covered when more tests are run #17

kubawerlos opened this issue Jun 2, 2019 · 17 comments

Comments

@kubawerlos
Copy link
Contributor

Hello,

I've spot an issue that some lines are not covered when tests are run together with other ones.

Easiest way to reproduce is to clone this repository: git clone git@github.com:kubawerlos/php-cs-fixer-custom-fixers.git.

When running vendor/bin/phpunit tests/Fixer all fixers get covered, which is expected.

But when running vendor/bin/phpunit tests some fixers don't get covered fully (but only some) and always the problematic is function isRisky, e.g. InternalClassCasingFixer::isRisky.

I've tested with PCOV v1.0.3 and phpunit/php-code-coverage 7.0.4.

@krakjoe
Copy link
Owner

krakjoe commented Jun 2, 2019

You seem to have a non-standard directory setup ...

php -dpcov.directory=. -dpcov.exclude="~vendor~" vendor/bin/phpunit tests

That's likely what you are looking for ...

@kubawerlos
Copy link
Contributor Author

What do you mean by "non-standard"? The src-dev directory? I have removed it and all references to it and still facing the issue. It was all fine a month ago -> https://coveralls.io/builds/23169688 (AFAIR it was PCOV v1.0.2 then).

However, your suggestion fixes it, thanks 👍

@krakjoe
Copy link
Owner

krakjoe commented Jun 2, 2019 via email

@krakjoe krakjoe closed this as completed Jun 2, 2019
@kubawerlos
Copy link
Contributor Author

Doesn't seems so - there are tests that covers lines that are problematic right now - e.g. https://github.com/kubawerlos/php-cs-fixer-custom-fixers/blob/master/tests/Fixer/InternalClassCasingFixerTest.php#L19 - and as I mentioned, when running only tests from subdirectory tests/Fixer all is covered fine.

@krakjoe krakjoe reopened this Jun 2, 2019
@krakjoe
Copy link
Owner

krakjoe commented Jun 2, 2019

You're quite right, something doesn't look right ... (I'm at my keyboard properly now, looking) ...

@krakjoe
Copy link
Owner

krakjoe commented Jun 2, 2019

Can you please try the tip of develop (currently 1.1.0-dev) and patch vendor/phpunit/php-code-coverage/src/Driver/PCOV.php with this stop method:

    /**
     * Stop collection of code coverage information.
     */
    public function stop(): array
    {
        \pcov\stop();

        $waiting  = \pcov\waiting();
        $collect  = [];

        if ($waiting) {
            $collect = \pcov\collect(\pcov\inclusive, $waiting);

            if ($collect) {
                \pcov\clear(\pcov\coverage | \pcov\waiting);
            } else {
                \pcov\clear(\pcov\waiting);
            }
        }

        return $collect;
    }

I believe this produces correct results ?

@kubawerlos
Copy link
Contributor Author

@krakjoe
Copy link
Owner

krakjoe commented Jun 2, 2019

I managed to go one better, you no longer need to patch the PHP driver, just update pcov ... 1.0.4-dev (managed to not break compat, so don't need to bump to 1.1) ...

@krakjoe
Copy link
Owner

krakjoe commented Jun 2, 2019

Sorry about all the mess ...

@krakjoe krakjoe mentioned this issue Jun 2, 2019
@kubawerlos
Copy link
Contributor Author

Sorry about all the mess ...

No need to, thanks for the very quick fix 👍

@krakjoe
Copy link
Owner

krakjoe commented Jun 2, 2019

Very welcome.

@deyvisonrocha
Copy link

deyvisonrocha commented Aug 6, 2019

@krakjoe Can you get folders to coverage from the phpunit.xml?

@BHSPitMonkey
Copy link

I think something is still off here, and possibly related to #31 and #38 (my experience lines up with all of these issues). I have a <filter><whitelist> defined in phpunit.xml with some <directory> nodes and an <exclude> node, and those get processed and sent to the pcov driver by phpunit via sebastianbergmann/php-code-coverage. After executing a simple test (using either phpunit or paratest), the resulting test reports show everything as uncovered (including specific lines I know were executed).

If I phpdismod pcov && phpenmod xdebug, my simple test works exactly as expected. Surely php-code-coverage is sending the filter/whitelist to pcov properly, since I can see the source files/methods/lines listed in the coverage report output -- but they're all marked 0%.

@krakjoe
Copy link
Owner

krakjoe commented Dec 12, 2019

To clarify, php-code-coverage doesn't "send" or pass anything from phpunit configuration to pcov. pcov must be configured properly with pcov.directory.

@BHSPitMonkey
Copy link

BHSPitMonkey commented Dec 12, 2019 via email

@miceno
Copy link

miceno commented Apr 28, 2020

@BHSPitMonkey I agree with you, I expend two days testing pcov with no coverage results due to this issue... I finally found the description here and figured it out to use -dpcov.directory.

@trip-somers
Copy link

trip-somers commented May 8, 2020

Is it possible to run coverage on two folders? I basically have two /app folders -- one is legacy, and one is modern -- and it looks like the only alternative I have is to set directory to . and then exclude everything except those two folders. Is that really what I'd have to do?

EDIT: It looks like this works fine after just setting it to .. From there, it appears that the section of the phpunit.xml config is handling the rest of what I need.

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

6 participants