XDEBUG EXTENSION FOR PHP | DOCUMENTATION

Code coverage tells you which lines of script (or set of scripts) have been executed during a request. With this information you can for example find out how good your unit tests are.



Related Settings


xdebug.coverage_enable
Type: boolean, Default value: 1, Introduced in Xdebug 2.2
If this setting is set to 0, then Xdebug will not set-up internal structures to allow code coverage. This speeds up Xdebug quite a bit, but of course, Code Coverage Analysis won't work.

Related Functions


array xdebug_get_code_coverage()
Returns code coverage information

Returns a structure which contains information about which lines were executed in your script (including include files). The following example shows code coverage for one specific file:

Example:

<?php
    xdebug_start_code_coverage
();

    function 
a($a) {
        echo 
$a 2.5;
    }

    function 
b($count) {
        for (
$i 0$i $count$i++) {
            
a($i 0.17);
        }
    }

    
b(6);
    
b(10);

    
var_dump(xdebug_get_code_coverage());
?>  

Returns:

array
  '/home/httpd/html/test/xdebug/docs/xdebug_get_code_coverage.php' => 
    array
      5 => int 1
      6 => int 1
      7 => int 1
      9 => int 1
      10 => int 1
      11 => int 1
      12 => int 1
      13 => int 1
      15 => int 1
      16 => int 1
      18 => int 1

void xdebug_start_code_coverage( [int options] )
Starts code coverage

This function starts gathering the information for code coverage. The information that is collected consists of an two dimensional array with as primary index the executed filename and as secondary key the line number. The value in the elements represents the total number of execution units on this line have been executed.

Options to this function are: XDEBUG_CC_UNUSED Enables scanning of code to figure out which line has executable code. XDEBUG_CC_DEAD_CODE Enables branch analyzes to figure out whether code can be executed.


void xdebug_stop_code_coverage( [int cleanup=true] )
Stops code coverage

This function stops collecting information, the information in memory will be destroyed. If you pass "false" as argument, then the code coverage information will not be destroyed so that you can resume the gathering of information with the xdebug_start_code_coverage() function again.


 
 
This site and all of its contents are Copyright © 2002-2012 by Derick Rethans.
All rights reserved.