Home > php教程 > php手册 > body text

Xdebug Document (5) Code coverage analysis, xdebug document

WBOY
Release: 2016-07-06 14:25:33
Original
960 people have browsed it

Xdebug Document (5) Code coverage analysis, xdebug document

Code coverage analysis can let you know which line (or section) of the script is being executed when requested.

Related settings

xdebug.coverage_enable

Type: boolean, Default value: 1, starts with

Xdebug >= 2.2

If set to 0, Xdebug will not set up built-in structures to allow code analysis. This can speed up xdebug faster, but code coverage analysis will not work.

Related functions

boolean xdebug_code_coverage_started()

Returns a Boolean value to see if code coverage analysis has started.

Example:

<?<span>php
    </span><span>var_dump</span><span>(xdebug_code_coverage_started());

    xdebug_start_code_coverage();

    </span><span>var_dump</span><span>(xdebug_code_coverage_started());
</span>?>  
Copy after login

Returns:

bool(false)
Copy after login
bool(true)
Copy after login
 
Copy after login

array xdebug_get_code_coverage()

Returns a structure containing which line of the script (including referenced files) is being executed. The following shows an example of code coverage specifying a certain file:

Example:

<?<span>php
    xdebug_start_code_coverage();

    </span><span>function</span> a(<span>$a</span><span>) {
        </span><span>echo</span> <span>$a</span> * 2.5<span>;
    }

    </span><span>function</span> b(<span>$count</span><span>) {
        </span><span>for</span> (<span>$i</span> = 0; <span>$i</span> < <span>$count</span>; <span>$i</span>++<span>) {
            a(</span><span>$i</span> + 0.17<span>);
        }
    }

    b(</span>6<span>);
    b(</span>10<span>);

    </span><span>var_dump</span><span>(xdebug_get_code_coverage());
</span>?>  
Copy after login

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] )

Start code coverage analysis

This function starts collecting code coverage information. This information is formed by a two-dimensional array. The first-dimensional index is the execution file name and the second-dimensional index is the line number. The element value indicates whether the line was executed or it has unreachable lines.

Value returned for each row:

  • 1: This line has already been executed
  • -1: This line has not been executed
  • -2: This line has no executable code

The -1 value will only be returned when XDEBUG_CC_UNUSED is turned on, and the -2 value will be returned only when XDEBUG_CC_UNUSED and XDEBUG_CC_DEAD_CODE are turned on at the same time.

The function has two options with enumeration values:

XDEBUG_CC_UNUSED

Enable code detection and indicate which lines of code are executable. Without this item, the returned array only contains the actual executed line numbers.

XDEBUG_CC_DEAD_CODE

Start additional analysis to show which code can be executed.

If these options are enabled, code coverage analysis will be significantly slowed down.

The following examples show how to use the options:

Example:

<?<span>php
xdebug_start_code_coverage( XDEBUG_CC_UNUSED </span>|<span> XDEBUG_CC_DEAD_CODE );
</span>?>
Copy after login

void xdebug_stop_code_coverage( [int cleanup=true] )

Stop code coverage analysis

This function stops collecting information and the information will be cleared in memory. If you pass the "false" parameter, the code coverage information will not be cleared and you can use xdebug_start_code_coverage() again to resume information collection.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template