View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001467XdebugCode Coveragepublic2017-09-11 15:232017-09-20 21:49
Assigned Toderick 
StatusresolvedResolutionno change required 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0001467: If a function call is splitted into multiple lines then arguments are counted as not covered by tests
DescriptionIf 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;
$lang_id = $source = $lexemes_ids = $deadline_ts = $skip_lexem_ids = 1;
$Obj = new Ololo();
$coverage = xdebug_get_code_coverage()[__FILE__];
$lines = file(__FILE__);
foreach ($lines as $idx => $l) {
    echo (isset($coverage[$idx + 1]) ? "\e[32m" : "\e[31m") . "$idx:$l";
TagsNo tags attached.
Operating System
PHP Version
Attached Files

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

-  Notes
CJ Dennis (reporter)
2017-09-12 12:33

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 (reporter)
2017-09-12 12:40

@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 (reporter)
2017-09-12 12:44

I can't attach a file due to an error in DB collation, this is a screenshot of the example code [^]
CJ Dennis (reporter)
2017-09-13 00:04

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. [^]
derick (administrator)
2017-09-20 21:49

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: [^]

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 15:23 Alexey New Issue
2017-09-12 12:33 CJ Dennis Note Added: 0004406
2017-09-12 12:40 Alexey Note Added: 0004407
2017-09-12 12:44 Alexey Note Added: 0004408
2017-09-13 00:04 CJ Dennis Note Added: 0004409
2017-09-20 21:42 derick Relationship added has duplicate 0001468
2017-09-20 21:42 derick Relationship added has duplicate 0001469
2017-09-20 21:49 derick Note Added: 0004415
2017-09-20 21:49 derick Status new => resolved
2017-09-20 21:49 derick Resolution open => no change required
2017-09-20 21:49 derick Assigned To => derick

Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker