PHP Continuous Integration with phpUnderControl

Many other technologies have enjoyed continuous integration environments for some time, but PHP has continually been on the outside looking in. For those who aren’t aware, continuous integration is the process of continually building code and running tests against it, keeping stats on the results of the tests. The most well-known of these is CruiseControl, a Java-based server which revolutionized how many developers think about development, helping Test Driven Development to take hold in many places it might not otherwise have. By having your project build and automatically report any errors every few minutes, you have a quick feedback loop which really helps people see and fix errors almost as they happen, while they are ‘top of mind’, rather than weeks or months later, or even better, when the original developer is gone.

Enter phpUnderControl, a set of add-ons for a standard Java-based CruiseControl server which bring tie together some PHP-specific tools with PHP-specific reporting screens. There’s some good basic documentation at the phpUC website, but it wasn’t enough for me. I have this knack of almost never being able to get by with *just* whatever docs people provide, in that I always run in to use cases which aren’t anticipated. So, both to help myself with a resource to come back to, and perhaps to help you as well, here’s a few issues that were roadblocks that I needed to deal with.

Installation

First, the main doc page starts off by saying that once you have a cruisecontrol server set up, you just need to do an svn checkout of phpUC, and “That’s it”. Very odd, because there’s a couple steps you need to do which are only mentioned at the *very* end of the documentation pages, and doesn’t seem to be listed as a ‘need to do’.

Jump down to the ‘command line’ section, and follow the command which says “To patch your CruiseControl installation you must execute the “install” command.” It’s not explained what “patching” your CC install will do, but it will change the graphics, and also adds some xsl files for processing the output for the PHP-specific tools (phpunit, phpdoc, phpcs).

PHPCS

phpUC has support for running a PHP Code Sniffer utility which will analyze your code for ‘style’ violations (indentation, formatting, and other things). Personally, I’ve just shut this off altogether by removing all references to phpcs from a project’s build.xml, or not putting it in the in the first place. If you followed the installation instructions and managed to install the example project “php-under-control”, take out references to php-codesniffer in the ‘depends’ attribute of the build.xml ‘build’ target.

PMD

This “Project Mess Detector” is formatted output from phpUnit giving scores to sections of files, rating them as to how bad the code is. Bad can be measured by a variety of metrics, and more information is here at Sebastian Bergmann’s blog. While neat, you may get overwhelmed by all the information there. To turn off the PMD calculations, but keep other aspects of the code coverage running, store this XML in a file called “phpunit-config.xml” and put it in your project’s base dir, parallel with the build.xml:

<?xml version=”1.0″?>
<phpunit>
<logging>
<pmd>
<rule class=”PHPUnit_Util_Log_PMD_Rule_Function_CodeCoverage” threshold=”-1,-1″/>
</pmd>
</logging>
</phpunit>

Then in your project’s build.xml file, add –configuration ${basedir}/phpunit-config.xml to the phpunit target’s “arg” tag with the other configuration flags.

Hosting

If your host doesn’t support Java, you can always install everything locally and run it there.  If you’re interested in external phpUC hosting, drop me a line – this is something I’m considering putting together as an offering.

Questions?

These are just some off-the-cuff notes that I’ve put together over the past couple of days setting up phpUnderCover. If you have some specific questions, let me know. I plan to put up some sample build.xml and config.xml files, along with more information about how I’ve set up continuous integration with phpUnderCover.

Share and Enjoy:
  • del.icio.us
  • DZone
  • Facebook
  • Reddit
  • StumbleUpon
  • Digg
  • Simpy
  • Technorati


0.18417096138