search
Homephp教程php手册Xdebug Document (5) Code coverage analysis, xdebug document

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.

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>?>  

Returns:

bool(false)
bool(true)
 

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>?>  

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>?>

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.

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)