Giter Site home page Giter Site logo

alvarlaigna / php-code-coverage Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sebastianbergmann/php-code-coverage

1.0 3.0 0.0 907 KB

Library that provides collection, processing, and rendering functionality for PHP code coverage information.

License: Other

php-code-coverage's Introduction

PHP_CodeCoverage

PHP_CodeCoverage is a library that provides collection, processing, and rendering functionality for PHP code coverage information.

Installation

PHP_CodeCoverage should be installed using the PEAR Installer. This installer is the backbone of PEAR, which provides a distribution system for PHP packages, and is shipped with every release of PHP since version 4.3.0.

The PEAR channel (pear.phpunit.de) that is used to distribute PHP_CodeCoverage needs to be registered with the local PEAR environment. Furthermore, a component that PHP_CodeCoverage depends upon is hosted on the eZ Components PEAR channel (components.ez.no).

sb@ubuntu ~ % pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

sb@ubuntu ~ % pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded

This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:

sb@vmware ~ % pear install phpunit/PHP_CodeCoverage
downloading PHP_CodeCoverage-0.9.0.tgz ...
Starting to download PHP_CodeCoverage-0.9.0.tgz (108,376 bytes)
.........................done: 108,376 bytes
install ok: channel://pear.phpunit.de/PHP_CodeCoverage-0.9.0

After the installation you can find the PHP_CodeCoverage source files inside your local PEAR directory; the path is usually /usr/lib/php/PHP/CodeCoverage.

Using the PHP_CodeCoverage API

<?php
require_once 'PHP/CodeCoverage.php';
require_once 'PHP/CodeCoverage/Report/Clover.php';
require_once 'PHP/CodeCoverage/Report/HTML.php';

$coverage = new PHP_CodeCoverage;
$coverage->start('<name of test>');

// ...

$coverage->stop();

$writer = new PHP_CodeCoverage_Report_Clover;
$writer->process($coverage, '/tmp/clover.xml');

$writer = new PHP_CodeCoverage_Report_HTML;
$writer->process($coverage, '/tmp/code-coverage-report');

Using the phpcov tool

sb@vmware examples % cat add.php
<?php
$a = 1;
$b = 2;
print $a + $b;

sb@vmware examples % phpcov --clover clover.xml add.php
phpcov 0.9.0 by Sebastian Bergmann.

3

sb@vmware examples % cat clover.xml
<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1270365900">
  <project timestamp="1270365900">
    <file name="/usr/local/src/bytekit-cli/examples/add.php">
      <line num="2" type="stmt" count="1"/>
      <line num="3" type="stmt" count="1"/>
      <line num="4" type="stmt" count="1"/>
      <line num="5" type="stmt" count="1"/>
      <metrics loc="4" ncloc="4" classes="0" methods="0"
               coveredmethods="0" conditionals="0"
               coveredconditionals="0" statements="4"
               coveredstatements="4" elements="4"
               coveredelements="4"/>
    </file>
    <metrics files="1" loc="4" ncloc="4" classes="0" methods="0"
             coveredmethods="0" conditionals="0"
             coveredconditionals="0" statements="4"
             coveredstatements="4" elements="4"
             coveredelements="4"/>
  </project>
</coverage>

php-code-coverage's People

Contributors

sebastianbergmann avatar fabpot avatar mbeccati avatar mattleff avatar

Stargazers

Alvar Laigna avatar

Watchers

Alvar Laigna avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.