View Issue Details

IDProjectCategoryView StatusLast Update
0001467XdebugCode Coveragepublic2017-09-20 20:49
ReporterAlexey Assigned Toderick  
PriorityimmediateSeverityblockReproducibilityalways
Status resolvedResolutionno change required 
Summary0001467: If a function call is splitted into multiple lines then arguments are counted as not covered by tests
Description

If a function call is splitted into multiple lines then arguments are counted as not covered by tests.

We have to format our code, it's vital.

Steps To Reproduce

<?php
class Ololo
{
public function omg($a, $b, $c, $d, $e)
{
$a + $b + $c;
}
}
xdebug_start_code_coverage();
$lang_id = $source = $lexemes_ids = $deadline_ts = $skip_lexem_ids = 1;
$Obj = new Ololo();
$Obj->omg(
$lang_id,
$source,
$lexemes_ids,
$deadline_ts,
$skip_lexem_ids
);
$coverage = xdebug_get_code_coverage()[FILE];
xdebug_stop_code_coverage();
$lines = file(FILE);
foreach ($lines as $idx => $l) {
echo (isset($coverage[$idx + 1]) ? "\e[32m" : "\e[31m") . "$idx:$l";
}
print_r($coverage);

TagsNo tags attached.
Operating System
PHP Version

Relationships

has duplicate 0001468 resolvedderick If a function call is splitted into multiple lines then arguments are counted as not covered by tests 
has duplicate 0001469 resolvedderick If a function call is splitted into multiple lines then arguments are counted as not covered by tests 

Activities

CJ Dennis

2017-09-12 11:33

reporter   ~0004406

I believe this is normal PHP behaviour. The parameters within the function call are not executed, only the commas, as they are doing some "work" by separating the parameters. Try placing each comma on a line by itself and testing it again.

In fact, it's interesting to place every token on a line of its own and see what PHP considers executed. All the open parentheses are executed, all the commas, some of the closing parentheses, some of the semicolons, the second plus and the closing brace of the method.

Alexey

2017-09-12 11:40

reporter   ~0004407

@CJ Dennis , sorry, but we have internal code formatting standards.

The problem is not in php, but in coverage calculation.
It doesn't matter whether php executes a line or not, the algorithm should consider such issues. IMHO

Alexey

2017-09-12 11:44

reporter   ~0004408

I can't attach a file due to an error in DB collation, this is a screenshot of the example code https://drive.google.com/file/d/0Byxfc0fklW5NbEpKTjFhbVlqcHc/view?usp=sharing

CJ Dennis

2017-09-12 23:04

reporter   ~0004409

If you use Codeception, which is powered by PHPUnit, which is powered by Xdebug, you'll see that there are four possible statuses for each line:

green - executed during the last run
yellow - dead code. This code is executable, but unreachable. e.g. all the code up to and including the } after a unconditional return;
white - not executable (not 100% accurate, but close enough)
red - not executed during the last run

The results you are getting are already correct. The red lines you want green are actually white in Codeception's HTML coverage report (i.e. Codeception reports 100% coverage of your test file). You need to educate whoever is responsible for your code standards. I would suggest using Codeception to see the issue more clearly. http://codeception.com/docs/11-Codecoverage

derick

2017-09-20 20:49

administrator   ~0004415

They are not covered, but they're also not considered as executable code. What CJ wrote is correct. PHP simply does not see code on these lines:

https://3v4l.org/8YFSF/vld#output

If you start code coverage as follows, you will see the four different states:

xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );

Issue History

Date Modified Username Field Change
2017-09-11 14:23 Alexey New Issue
2017-09-12 11:33 CJ Dennis Note Added: 0004406
2017-09-12 11:40 Alexey Note Added: 0004407
2017-09-12 11:44 Alexey Note Added: 0004408
2017-09-12 23:04 CJ Dennis Note Added: 0004409
2017-09-20 20:42 derick Relationship added has duplicate 0001468
2017-09-20 20:42 derick Relationship added has duplicate 0001469
2017-09-20 20:49 derick Note Added: 0004415
2017-09-20 20:49 derick Status new => resolved
2017-09-20 20:49 derick Resolution open => no change required
2017-09-20 20:49 derick Assigned To => derick