[xdebug-general] Re: Code Coverage of "non PHP code"

From: Andres Riancho <andres.riancho[@]gmail.com>
Date: Sun, 21 Mar 2010 12:25:04 -0300

Derick,

    Thank you very much for your answer, please read inline,

On Sat, Mar 20, 2010 at 8:12 PM, Derick Rethans <derick[@]xdebug.org> wrote:
> On Sat, 20 Mar 2010, Andres Riancho wrote:
>
>>     Never returns 1. In this case it will return 3/8. (there are other
>> extra issues here like xdebug not counting lines 1, 2 and 3, but I can
>> solve that by using PHP's prepend_file and append_file).
>
> The best way is too enable two options to xdebug_start_code_coverage,
> like:
>
> xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
>
> this gives an overview of all lines where PHP thinks there is code. This
> only works if the file in which the code runs has *not* been executed
> yet. You'll have to put the code in an include file

    I have this setup:

---test.php---
<? echo "A"; ?>
AAA
<? if( 1 ){ ?>
BBB
<? }else{ ?>
CCC
<? } ?>
8
9
10
11
12
13
---test.php---

---header.php---
<?php

  // Starting code coverage analysis
  xdebug_start_code_coverage( XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
?>
---header.php---

---footer.php---
<?php
    $cc_info = xdebug_get_code_coverage();
    xdebug_stop_code_coverage();
    var_dump($cc_info);
?>
---footer.php---

header.php and footer.php are setup in prepend and append file in
php.ini. When I enter the test.php I'm getting:

---output---
  '/var/www/moth/test.php' =>
    array
      0 => int 1
      1 => int 1
      3 => int 1
      5 => int 1
      7 => int -1
      14 => int 1
---output---

    There are a couple of things that I'm not understanding from this output:

- Why is the output starting at line number 0?
- Why do I have a -1 in line 7? Shouldn't that be line 5 if xdebug
starts counting from 0, or line 6 if it starts counting from 1?
- What happend with lines 8 to 13?

    What I would expect as output for this test.php script is:

---output---
  '/var/www/moth/test.php' =>
    array
      1 => int 1
      2 => int 1
      3 => int 1
      4 => int 1
      5 => int 1
      6 => int -1
      7 => int 1
      8 => int 1
      9 => int 1
      10 => int 1
      11 => int 1
      12 => int 1
      13 => int 1
      14 => int 1
---output---

> , something like the
> test case here:
>
> http://svn.xdebug.org/cgi-bin/viewvc.cgi/xdebug/trunk/tests/bug00515.phpt?view=markup&revision=2899&root=xdebug

    All I see in this URL is a python traceback.

> (which includes:
>
> <?php
> declare(ticks=1);
> class UncoveredLine
> {
>    private $_foo;
>
>    function __construct($foo)
>    {
>        if ($foo === 'bar') {
>            $this->_foo = $foo;
>        } else {
>            $this->_foo = null;
>        }
>    }
>
>    function getFoo()
>    {
>     return $this->_foo;
>    }
> }
> ?>
>
> Also see:
> http://xdebug.org/docs/code_coverage#xdebug_start_code_coverage
>
> with kind regards,
> Derick
>
> --
> Like Xdebug? Consider a donation: http://xdebug.org/donate.php
> Xdebug | http://xdebug.org | xdebug-general@lists.xdebug.org
> twitter: @derickr and @xdebug
>

-- 
Andrés Riancho
Founder, Bonsai - Information Security
http://www.bonsai-sec.com/
http://w3af.sf.net/
Received on Sun Mar 21 2010 - 15:25:25 GMT

This archive was generated by hypermail 2.2.0 : Mon Jun 25 2018 - 06:00:04 BST