CRAP in PHPUnit 3.5

Sebastian Bergmann » 12 January 2010 » in New Features » 6 Comments

For the upcoming PHPUnit 3.5, I have factored out all code that is related to code coverage and put it into a separate component: PHP_CodeCoverage.

PHP_CodeCoverage is a component that provides collection, processing, and rendering functionality for PHP code coverage information. It makes PHPUnit's mature code coverage functionality available outside of PHPUnit.

Having all code that deals with code coverage in a separate component allows for easier development and better testing. The first result of these improved development conditions is a small new feature that I recently implemented, the support for the CRAP metric.

From crap4j.org:

The CRAP (Change Risk Analysis and Predictions) software metric [has] a mildly offensive metric name [and helps] to help protect you from truly offensive code.

The CRAP metric combines cyclomatic complexity and code coverage from automated tests (e.g. [PHPUnit] tests) to help you identify code that might be particularly difficult to understand, test, or maintain — the kind of code that makes developers say: “This is crap!” or, if they are stuck maintaining it, “Oh, crap!”.

The screenshot below shows how the CRAP metric is reported in the HTML code coverage report:

Code Coverage Report
Defined tags for this entry: , ,

Trackback specific URI for this entry

6 Comments to "CRAP in PHPUnit 3.5"

Display comments as (Linear | Threaded)
  1. Cristiano
    12/01/2010 at 14:49 Permalink
    Trully an offensive name, but it does helps while writing code with great standards. I'm using PHPUnit for last 12 months and using code coverage actually helps the application to be much more reliable.

    Reply

  2. fritz
    13/01/2010 at 19:21 Permalink
    You really should try and come up with a better name for this - it will never be taken seriously in some circles with a name like that.

    Reply

  3. Matthew Weier O'Phinney
    18/01/2010 at 15:58 Permalink
    Note that Sebastian didn't come up with the name -- it's a concept that's been used in Java and other languages for some time.

    Reply

  4. Łukasz Wojciechowski
    04/02/2010 at 03:18 Permalink
    Hi All

    I have just tried PHP_CodeCoverage package and it is working great.
    Just what I needed :)

    Thanks Sebastian

    However I was wondering if this package is available from phpunit pear channel.

    I tried to guess package name/version/state but without luck :/

    --
    Best regards

    Reply

  5. Sebastian Bergmann
    04/02/2010 at 03:39 Permalink
    PHP_CodeCoverage is still under heavy development and as long as the API have not stabilized I won't roll a release.

    The first stable release (1.0.0) will coincide with the release of PHPUnit 3.5.

    Reply

  6. James Brisland
    11/02/2010 at 14:10 Permalink
    Hi Sebastian,

    I've been digging around in the PHP_CodeCoverage code trying to figure out how I can get it working with Moodle and SimpleTest.

    I am aiming to try and get our Moodle installation working with PHPUnit, but that is going to take a while (unless you have the automatic conversion scripts from SimpleTest->PHPUnit done, I see others have asked for this in the past and you have said it was something you where considering).

    Is there any chance I could grab some time at some point to discuss this, or is there any simple test cases where you have PHP_CodeCoverage working using xdebug with some sample code that isn't PHPUnit.

    If you could reply to my email (I guess you should be able to see the one I attached to this post) that would be great, but only if and when you have some spare time (as I know time is a precious!)

    This would be great for the testing community in general. I know it would be running under something other than PHPUnit, but I'm guessing it should still be able to work as all it takes is the xdebug output and a list of files (white and blacklist I guess?)

    Regards,

    James Brisland

    Reply

3 Trackbacks to "CRAP in PHPUnit 3.5"

  1. Sebastian Bergmann 03/04/2010 at 19:15
    Almost a year ago I started to factor out all the code that deals with code coverage in PHPUnit and put into a separate component. The name of this component is PHP_CodeCoverage.PHP_CodeCoverage is a library that provides collection, processing, and rende
  2. andytson.com 17/05/2010 at 16:18
  3. www.phphatesme.com 28/07/2010 at 07:01

Add Comment


To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

Submitted comments will be subject to moderation before being displayed.