On PHPUnit and Software Metrics

Sebastian Bergmann » 06 February 2008 » in New Features » 0 Comments

Manuel Pichler's recent blog entry on PHP_Depend prompted me to write about my opinion on the future of software metrics and project mess detection in PHPUnit.

When I started to work on these projects, there was no other place for me then to develop them as part of PHPUnit. There was no phpUnderControl yet, and PHPUnit already had some utility classes that provided the neccessary infrastructure to quickly implement software metrics.

But the more I thought about it, I realized that these features do not belong into PHPUnit but into a suite of tools that PHPUnit is a well-integrated part of. However, given the fact that PHPUnit's development takes place in the open and people were already eagerly waiting for the software metrics and project mess detection support, I decided -- against my better judgement -- to release the functionality in question as part of PHPUnit 3.2.

Now that tools such as PHP_CodeSniffer get the attention they deserve and need and that tools such as phpUnderControl and PHP_Depend are being developed, I think it is time to take the software metrics functionality out of PHPUnit (see changeset 2377). This will not happen over night, though. The features in question will be marked as being deprecated for PHPUnit 3.3 before they will be removed in PHPUnit 3.5. Work has already begun (see changeset 2351) on the required integration between projects such as PHPUnit (which provides Code Coverage information in XML format) and PHP_CodeSniffer (which calculates, for instance, the Cyclomatic Complexity software metrics) so that phpUnderControl process these two inputs in order to calculate the Change Risk Analysis and Predictions (CRAP) index.
Defined tags for this entry: , , , ,

phpUnderControl

Sebastian Bergmann » 19 November 2007 » in PHPUnit » 4 Comments

Manuel Pichler recently released phpUnderControl. As of today phpUnderControl is hosted on phpunit.de.

phpUnderControl aims to make the first steps with CruiseControl and PHP as easy as possible. It integrates three of the best PHP development tools into CruiseControl, combined with an easy setup routine and a small example project. With the provided XSL stylesheets, the generated output of PHPUnit, PHP_CodeSniffer and phpDocumentor can be visualized in CruiseControl.
Defined tags for this entry: , , , , ,

Qualitätssicherung in PHP-Projekten

Sebastian Bergmann » 06 November 2007 » in Presentations » 0 Comments

Defined tags for this entry: , , , ,

Copy & Paste Detection in PHPUnit 3.2

Sebastian Bergmann » 22 August 2007 » in New Features » 0 Comments

Version 3.2 of PHPUnit is shaping up nicely. In this blog posting I want to highlight another aspect of PHPUnit's new Project Mess Detector feature set.

Duplicate code can be hard to find, especially in a large project. Johann-Peter Hartmann of MAYFLOWER GmbH recently implemented Copy & Paste Detection for PHPUnit's growing set of features that extends its usage scenarios beyond "just unit testing" to a one-stop solution for quality assurance in PHP-based projects.

Here is an example of how PHPUnit 3.2 will report code duplication:
<?xml version="1.0" encoding="UTF-8"?>
<pmd-cpd version="PHPUnit 3.2.0">
  <duplication lines="12" tokens="56">
    <file path="/usr/local/src/ezcomponents/trunk/Graph/src/driver/svg.php"
               line="197"/>
    <file path="/usr/local/src/ezcomponents/trunk/Graph/src/driver/svg.php"
               line="248"/>
    <codefragment><![CDATA[
if ( !in_array( $color->__toString(), $this->drawnGradients, true ) )
{
    $gradient = $this->dom->createElement( 'linearGradient' );
    $gradient->setAttribute( 'id', 'Definition_' . $color->__toString() );
    $this->defs->appendChild( $gradient );

    // Start of linear gradient
    $stop = $this->dom->createElement( 'stop' );
    $stop->setAttribute( 'offset', 0 );
    $stop->setAttribute(
      'style',
      sprintf( 'stop-color: #%02x%02x%02x; stop-opacity: %.2F;',
               $color->startColor->red,
               $color->startColor->green,
]]></codefragment>
  </duplication>
Defined tags for this entry: , , ,

PHPUnit as a Project Mess Detector

Sebastian Bergmann » 09 August 2007 » in New Features » 4 Comments

PMD, also known as Project Mess Detector, is a popular tool in the Java world that scans Java source code and looks for potential problems. It is well integrated with other tools such as Eclipse or CruiseControl, making the collected information available at multiple points throughout the development process.

Why am I blogging about this? Well. As of version 3.2, PHPUnit will not only be able to calculate and collect a variety of software metrics. It will also be able to report violations of rules that are based on these metrics in PMD's XML format. This information can then be fed to any tool that integrates with PMD.

For starters I implemented the code size rules that take, among other information, the Lines of Executable Code (ELOC), Cyclomatic Complexity, and NPath Complexity metrics into account.
Defined tags for this entry: , , ,