• Stars
    star
    695
  • Rank 65,093 (Top 2 %)
  • Language
    C
  • License
    Other
  • Created almost 6 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

PCOV - CodeCoverage compatible driver for PHP

PCOV

Build Status Build status

A self contained CodeCoverage compatible driver for PHP

Requirements and Installation

See INSTALL.md

API

/**
 * Shall start recording coverage information
 */
function \pcov\start() : void;

/**
 * Shall stop recording coverage information
 */
function \pcov\stop() : void;

/**
 * Shall collect coverage information
 *
 * @param integer $type define witch type of information should be collected
 *		 \pcov\all        shall collect coverage information for all files
 *		 \pcov\inclusive  shall collect coverage information for the specified files
 *		 \pcov\exclusive  shall collect coverage information for all but the specified files
 * @param array $filter path of files (realpath) that should be filtered
 *
 * @return array
 */
function \pcov\collect(int $type = \pcov\all, array $filter = []) : array;

/**
 * Shall clear stored information
 *
 * @param bool $files set true to clear file tables
 *
 * Note: clearing the file tables may have surprising consequences
 */
function \pcov\clear(bool $files = false) : void;

/**
 * Shall return list of files waiting to be collected
 */
function \pcov\waiting() : array;

/**
 * Shall return the current size of the trace and cfg arena
 */
function \pcov\memory() : int;

Configuration

PCOV is configured using PHP.ini:

Option Default Changeable Description
pcov.enabled 1 SYSTEM enable or disable zend hooks for pcov
pcov.directory auto SYSTEM,PERDIR restrict collection to files under this path
pcov.exclude unused SYSTEM,PERDIR exclude files under pcov.directory matching this PCRE
pcov.initial.memory 65536 SYSTEM,PERDIR shall set initial size of arena
pcov.initial.files 64 SYSTEM,PERDIR shall set initial size of tables

Notes

The recommended defaults for production should be:

  • pcov.enabled = 0

The recommended defaults for development should be:

  • pcov.enabled = 1
  • pcov.directory = /path/to/your/source/directory

When pcov.directory is left unset, PCOV will attempt to find src, lib or, app in the current working directory, in that order; If none are found the current directory will be used, which may waste resources storing coverage information for the test suite.

If pcov.directory contains test code, it's recommended to set pcov.exclude to avoid wasting resources.

To avoid unnecessary allocation of additional arenas for traces and control flow graphs, pcov.initial.memory should be set according to the memory required by the test suite, which may be discovered with \pcov\memory().

To avoid reallocation of tables, pcov.initial.files should be set to a number higher than the number of files that will be loaded during testing, inclusive of test files.

Note that arenas are allocated in chunks: If the chunk size is set to 65536 and pcov require 65537 bytes, the system will allocate two chunks, each 65536 bytes. When setting arena space therefore, be generous in your estimates.

Interoperability

When PCOV is enabled by configuration pcov.enabled=1:

  • interoperability with Xdebug is not possible
  • interoperability with phpdbg is not possible
  • interoperability with Blackfire profiler is not possible

At an internals level, the executor function is overriden by pcov, so any extension or SAPI which does the same will be broken.

When PCOV is disabled by configuration pcov.enabled=0:

  • PCOV is zero cost - code runs at full speed
  • Xdebug may be loaded
  • phpdbg may be executed
  • Blackfire probe may be loaded

At an internals level, the executor function is untouched, and pcov allocates no memory.

Differences in Reporting

There are subtle differences between Xdebug and PCOV in reporting: Both Xdebug and PCOV perform branch analysis in order to detect executable code. Xdebug has custom written (very mature, proven) analysis, while PCOV uses the very well proven control flow graph from Optimizer. They generate comparably accurate reports, while phpdbg uses less robust detection of executable code and generates reports with known defects. One such defect in phpdbg is this:

/* 2 */ function foo($bar) {
/* 3 */ 	if ($bar) {
/* 4 */			return true;
/* 5 */		}
/* 6 */	}

phpdbg will detect that this function is 100% covered when the first control path is taken, if ($bar), because it cannot correctly detect which implicit return paths inserted by Zend at compile time are executable, and so chooses to ignore them all. While this may seem like a trivial difference to some, it means that the reports generated by phpdbg are not completely trustworthy.

While the accuracy of Xdebug and PCOV are comparable, the reports they generate are not precisely the same, one such example is the switch construct:

/* 2 */ switch ($condition) {
/* 3 */		case 1:
/* 4 */			return "PHP rox!";
/* 5 */	}

From PHP 7.2.15 and PCOV 1.0, PCOV will detect the executability of the cases inside the switch body correctly, but will not detect line 2 (with the switch statement) as executable because Zend didn't output an executable opcode on that line. Xdebug's custom analysis doesn't use the same method and so will show an extra executable line on 2. Pre 7.2.15 and PCOV 1.0, the coverage of some switches is questionable as a result of the way Zend constructs the opcodes in the body of the switch - it may not execute them depending on a jump table optimization.

While Xdebug and PCOV both do the same kind of analysis of code, Xdebug is currently able to do more with that information than just generate accurate line coverage reports, it has path coverage and PCOV does not, although path coverage is not yet implemented (and probably won't be) by CodeCoverage.

Differences in Performance

The differences in performance of Xdebug and PCOV are not slight. Xdebug is first and foremost a debugging extension, and when you load it, you incur the overhead of a debugger even when it's disabled. PCOV is less than 1000 lines of code (not including CFG) and doesn't have anything like the overhead of a debugger.

More Repositories

1

pthreads

Threading for PHP - Share Nothing, Do Everything :)
C
3,471
star
2

parallel

A succinct parallel concurrency API for PHP8
C
1,448
star
3

apcu

APCu - APC User Cache
C
964
star
4

phpdbg

The Interactive PHP Debugger
C
837
star
5

ui

Cross platform UI development in PHP
C
516
star
6

tombs

Detect unused code in production
C
428
star
7

uopz

User Operations for Zend
C
354
star
8

stat

A super modern high performance profiler for production
C
209
star
9

jitfu

Creating native instructions in PHP since 2014
C
191
star
10

explain

Explain
JavaScript
110
star
11

pthreads-polyfill

A polyfill for pthreads
PHP
80
star
12

ilimit

Limit time and memory consumption of individual calls
C
70
star
13

idbg

Inspector Debugger
PHP
70
star
14

wkhtmltox

Converting HTML to X since 2017
C
66
star
15

promises

Promises in PHP
PHP
64
star
16

ustring

UnicodeString for PHP7
C++
64
star
17

autostrict

Automatic strict types in PHP7
C
64
star
18

inspector

Disassembler and Debug Kit for PHP 7
C
55
star
19

sandbox

A sandbox environment for PHP7.1+
C
54
star
20

cmark

CommonMark for PHP
C
46
star
21

mimus

mocking framework as light as a bird ...
PHP
46
star
22

pcov-clobber

Run PCOV in versions of PHPUnit before 8, if you must ...
PHP
40
star
23

componere

Complex Type Composition and Manipulation
C
39
star
24

apcu-bc

APCu Backwards Compatiblity Module
C
33
star
25

SIMD

Single Instruction, Multiple Data
C
30
star
26

pthreads-autoloading-composer

An example of how to use composers autoloader in conjunction with Pools
PHP
29
star
27

memoize

Caching the result of your expensive function calls since 2016
C
23
star
28

profiler

An extension to profile PHP
C
19
star
29

php-jansson

jannson based json encoder and decoder for PHP
C
18
star
30

trace

Tracing for PHP7 Processes
C
18
star
31

snappy

Snappy Compression for PHP
PHP
15
star
32

indexed

Educational Extension for PHP7
C
13
star
33

router

This extension serves to provide a sane, easy router for modern PHP applications:
C
13
star
34

uref

weak refs, for the brave ...
C++
13
star
35

phpdbg-ui

phpdbg remote console client
Java
13
star
36

ponion

onion server for php
C
10
star
37

operators

Override operators in userland
C
9
star
38

HandlerSocket

HandlerSocket PHP 7 Extension
C
9
star
39

apcup

APCu Pooling
C
9
star
40

utypes

User verified types
C
9
star
41

overload

Overloading Zend (RESEARCH)
C
9
star
42

bundle

An experimental method of bundling PHP code with extensions
C
7
star
43

nocheq

Sick of pesky type checking making your code too slow (and correct) ?
C
7
star
44

kore

kore php functions
C
6
star
45

perf

Sampling Profiler for PHP 7 (Unfinished)
C
6
star
46

Object

Multiple Inheritance at Runtime
C
5
star
47

cmark-visitors

Visitors for CommonMark implementing some useful AST transformations
PHP
4
star
48

instrumental

Componere Instrumental
PHP
4
star
49

u2fh

PHP7 u2fh
C
4
star
50

u2fs

PHP7 u2fs
C
3
star
51

sysconf

Get configuration information at run time
C
3
star
52

jitfi

PHP FFI header for libjit
C
3
star
53

cloname

Demonstrate how to give closures long names
C
2
star
54

dec64

dec64
Assembly
2
star
55

transformer

C
2
star
56

zi

Zend Instruments
C
2
star
57

ohash

spl_object_hash alternative playground
C
1
star
58

ui-doc

Documentation Resources for UI
PHP
1
star
59

apcu-ps

APCu PS Module
C
1
star