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

Coverage in composer "files" autoload is not collected #958

Closed
mvorisek opened this issue Nov 11, 2022 · 12 comments
Closed

Coverage in composer "files" autoload is not collected #958

mvorisek opened this issue Nov 11, 2022 · 12 comments

Comments

@mvorisek
Copy link
Contributor

mvorisek commented Nov 11, 2022

Q A
php-code-coverage version 9.2.18, 9.2.19 / latest
PHP version 8.0.24
Driver Xdebug
Xdebug version 3.2.0RC1
Installation Method Composer
Usage Method PHPUnit
PHPUnit version 9.5.25

code: https://github.com/atk4/data/blob/e091b675d32a17d839e918557f3e24ab6211b563/bootstrap-types.php#L49

<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1668794616">
  <project timestamp="1668794616">
...
    <file name="/__w/data/data/bootstrap-types.php">
      <class name="Atk4\Data\Types\Types" namespace="global">
        <metrics complexity="0" methods="0" coveredmethods="0" conditionals="0" coveredconditionals="0" statements="0" coveredstatements="0" elements="0" coveredelements="0"/>
      </class>
      <class name="Atk4\Data\Types\MoneyType" namespace="global">
        <metrics complexity="8" methods="5" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="8" elements="13" coveredelements="13"/>
      </class>
      <line num="17" type="method" name="getName" visibility="public" complexity="1" crap="1" count="12"/>
      <line num="19" type="stmt" count="12"/>
...
      <line num="43" type="method" name="requiresSQLCommentHint" visibility="public" complexity="1" crap="1" count="12"/>
      <line num="45" type="stmt" count="12"/>
      <metrics loc="50" ncloc="50" classes="1" methods="5" coveredmethods="5" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="8" elements="13" coveredelements="13"/>
    </file>
...

image

simple repro code:

<?php

class Foo
{
    public function x(): void
    {
        phpversion(); // must be covered (currently covered)
    }
}

phpversion(); // must be covered too (currently NOT covered)

does not generate any coverage line (in clover output)

when the statement is added into method body, the coverage is generated, but for some reasons, coverage for statement outside/below method does not - maybe related to clover only, not sure

@mvorisek
Copy link
Contributor Author

@Slamdunk any idea?

@Slamdunk
Copy link
Contributor

9.2.21 fixed this

@mvorisek
Copy link
Contributor Author

You mean by #964? Why it was not covered before - what condition was missing - and is it tested now?

@Slamdunk
Copy link
Contributor

@mvorisek
Copy link
Contributor Author

mvorisek commented Feb 26, 2023

9.2.21 fixed this

@Slamdunk it did not fix it

retested with the latest version of this repo using atk4/data@f59e169:

image

issue is still present

@Slamdunk
Copy link
Contributor

I'll have a look on this next week

@Slamdunk
Copy link
Contributor

As far as I can tell, no issue is present.

In the original post of this topic #958 (comment) you reported that line 49 has not been marked as executable. 9.2.21 fixed that, and this issue should be closed.

#958 (comment) instead reports that lines 12 and 13 are not marked as covered. This has nothing to do with sebastianbergmann/php-code-coverage, which simply reports correctly that those two lines need to be tracked for code-coverage.
Code-coverage that is missing by your tests.

@mvorisek
Copy link
Contributor Author

(original) l49 is not different than the current 12/13. The code is always included here: https://github.com/atk4/data/blob/f59e169f33f7aa53587a76e0647efa0df5521fb9/composer.json#L71, ie. definitely executed.

@Slamdunk
Copy link
Contributor

(original) l49 is not different than the current 12/13.

Of course they are the same, but the issue you are reporting is different.
49 was white, so they were not considered as executable until 9.2.21.
12/13 are instead red, which means they are considered as executable.

https://github.com/atk4/data/blob/f59e169f33f7aa53587a76e0647efa0df5521fb9/composer.json#L71, ie. definitely executed.

It doesn't surprise me at all that they are marked as red: composer autoloads src/bootstrap-types.php much earlier than any code-coverage is activated by PHPUnit

@mvorisek
Copy link
Contributor Author

It doesn't surprise me at all that they are marked as red: composer autoloads src/bootstrap-types.php much earlier than any code-coverage is activated by PHPUnit

makes sense, do you think we can introduce some "pre test" coverage?

@sebastianbergmann
Copy link
Owner

I think we should stop worrying about code that is outside of classes and functions.

@mvorisek
Copy link
Contributor Author

maybe in the future

@mvorisek mvorisek changed the title Statement below class does not generate any coverage line Coverage in composer "files" autoload is not collected Feb 28, 2023
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