You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If using constructor property promotion in a single line while defining a new instance of an object, the clover report does not contain a line of type stmt but counts it as a statement in the metrics. On the other hand, every method is mentioned on it's own but I'm not able to distinguish a constructor with an kind of inline statement from a regular method without.
I hope the following two examples make it more clear. I've written both of them as unittests in php-code-coverage, but I'm not sure what the correct solution might be? Should there be a second line for the same num with type stmt? Is that even allowed in the clover format?
I've just played a bit further with it. The second example is wrong, if using real coverage. As I was using RawCodeCoverageData::fromXdebugWithoutPathCoverage() and marked line 6 as covered in the tests, it generated the given output of the second example.
It doesn't count the promoted property at all, if in multi-line mode. That's true for PCOV and Xdebug. But for single line, it makes no difference to use PCOV or Xdebug for coverage.
So the correct fix seems to be not counting the line as a statement?
The same behavior is true for the html reporting. If using a single line, it is counted as a statement, if using multi line, not.
So the correct fix seems to be not counting the line as a statement?
Exactly: the constructor countent is already handled correctly, there should be no CC line for ctor arguments in both cases.
I'd mark this as a low priority bug though: no false-positive nor false-negative possible, so I'll propose a fix once I'm done with my current job tasks, hopefully in a week
thirsch
changed the title
Incorrect statement count in clover coverage report for constructor property promotion
Incorrect statement count in coverage report for constructor property promotion
Oct 4, 2023
If using constructor property promotion in a single line while defining a new instance of an object, the clover report does not contain a line of type stmt but counts it as a statement in the metrics. On the other hand, every method is mentioned on it's own but I'm not able to distinguish a constructor with an kind of inline statement from a regular method without.
I hope the following two examples make it more clear. I've written both of them as unittests in php-code-coverage, but I'm not sure what the correct solution might be? Should there be a second line for the same num with type stmt? Is that even allowed in the clover format?
Example 1 (single line)
Generated clover.xml:
Please note the attributes "statements" and "coveredstatements" both being 2, but only one line of type stmt.
Example 2 (with linebreak)
Generated clover.xml:
The text was updated successfully, but these errors were encountered: