View Issue Details

IDProjectCategoryView StatusLast Update
0001830XdebugCode Coveragepublic2021-04-08 09:52
ReporterNeunerlei Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionwon't fix 
Product Version2.9.5 
Target Version3.0dev 
Summary0001830: "Use" Trait Statement marked as "executable" code
Description

Hello there,

as described here: https://github.com/sebastianbergmann/php-code-coverage/issues/790
and especially: https://github.com/sebastianbergmann/php-code-coverage/issues/790#issuecomment-671086908

it seems to be the case, that xdebug reports lines with "use" statements, to include class traits, as executable,
which breaks php-code-coverage.

The issue only appears on PHP 7.3 and not PHP 7.4 (I switched to 7.4 and it works there)

I hope this helps.
Thank you :)

TagsNo tags attached.
Attached Files
Operating SystemLinux
PHP Version7.3.10-7.3.14

Activities

derick

2020-08-11 12:26

administrator   ~0005439

Hi!

I'm going to need a short reproducible case.

In this, please only include the code that has and uses the trait, and causes this issue with code overage. I don't need or want any PHP Unit test case, composer library, etc.

cheers,
Derick

Neunerlei

2020-08-11 13:08

reporter   ~0005440

I'm not an author of the code-coverage library. Therefore I can't give you the details.
However while testing for the issue the minimal, reproducible setup were two files:

A.php:
<?php
declare(strict_types=1);

namespace Neunerlei\Arrays;

class A
{
use ATrait;
}

ATrait.php
<?php
declare(strict_types=1);

namespace Neunerlei\Arrays;

trait ATrait
{

}

In that case A.php:8 is marked as "not executed"

I resolved the issue for me, by migrating to PHP 7.4 where everything works as expected.

Martin

derick

2020-08-11 18:13

administrator   ~0005441

I think I see the problem. Will have a good look tomorrow.

Thanks!

derick

2021-04-08 09:52

administrator   ~0005822

Sorry, that that "tomorrow" became 6 months later.

I have had a long look at this, and I think I have come to the conclusion that I do not want to address this right now.

Code coverage analyses which code can be executed when code coverage is active, and a new scope (script, method, or function) is seen for the first time. When code then runs, it modifies this information with whether code has been executed when specific lines have been hit. When code coverage was implemented, it was never meant to be stopped and started between every test, but rather, collect information for the whole execution as all the tests in one go. This means that it is now impossible to reset the internal collected information to the analysed stated (which line is executable etc). The only way would be to reanalyse everything. And that'd be so slow that nobody would ever want to do code coverage again.

The only way to solve this is to split the "analyse what code can do what" and "collect which lines/etc have been hit" into two separate internal data stores, and merge that information when returning it with xdebug_get_code_coverage(). That's going to be a major undertaking (read: months), and I don't think I will have the time for that, considering all the other issues I want to fix, and features to add.

Considering that you no longer have this problem with PHP 7.4, and that PHP 7.3 and older are no longer supported, I feel OK with closing this issue.

Issue History

Date Modified Username Field Change
2020-08-10 19:37 Neunerlei New Issue
2020-08-11 12:26 derick Assigned To => derick
2020-08-11 12:26 derick Status new => feedback
2020-08-11 12:26 derick Note Added: 0005439
2020-08-11 13:08 Neunerlei File Added: 2020-08-11 15_07_10-Code Coverage for _var_www_html_neunerlei_arrays_Classes_A.php.png
2020-08-11 13:08 Neunerlei Note Added: 0005440
2020-08-11 13:08 Neunerlei Status feedback => assigned
2020-08-11 18:13 derick Status assigned => confirmed
2020-08-11 18:13 derick Note Added: 0005441
2021-03-17 08:45 derick Target Version => 3.0dev
2021-04-08 09:52 derick Status confirmed => resolved
2021-04-08 09:52 derick Resolution open => won't fix
2021-04-08 09:52 derick Note Added: 0005822