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

8 comments

  1. Hello Michael,

    really nice phpUnderControl post and some important hints on documentation lacks, that I will try to fix soon. You mention example build.xml and config.xml files that are already part of phpUnderControl and also linked within the main documentation.

    http://www.phpunit.de/browser/phpUnderControl/trunk/docs/config.xml
    http://www.phpunit.de/browser/phpUnderControl/trunk/docs/build.xml

    Maybe you haven’t found them before or you haven’t found them useful and can suggest some enhancements?

    Greetings

    Manuel

  2. I’d like to use phpUnderControl for our larger projects but the effort required to install, configure and maintain it is holding us back.

    A hosted solution would be very interesting.

  3. bholub says:

    I’m having an issue on windows… I’m going through the example app docs and I can get up through the “checkout” target. When I try any of the other targets I’m getting the error: C:\Program Files\CruiseControl\projects\phpundercontrol.org\build.xml:12: Execute failed: java.io.IOException: Cannot run program “phpdoc” (in directory “C:\Program Files\CruiseControl\projects\phpundercontrol.org\source”): CreateProcess error=2, The system cannot find the file specified

    I thought maybe it was a PATH issue, so I updated the build.xml file to exec “c:/php/phpdoc” instead and then I get: CreateProcess error=193, %1 is not a valid Win32 application

    It must be something dumb, I’m totally new to Java/ant/CruiseControl etc.

    Little help?

    Thanks,
    Brian

  4. bholub says:

    I think I may have found an answer to my problem. I’m not sure if it has anything to do with it, but my system is Windows XP running in a VMWare image on a Vista host (kinda crazy).

    Anyway, adding os=”Windows NT” to the executable tag seems to make it work…

  5. bholub says:

    Sigh… ignore that last comment, that just made the command not run :) The build was successful… and no errors were thrown, but that’s no good when nothing runs :) If you can just delete my (now-spammy) comments, I’ll post a solution when I find one… or if you can provide one.

    Thanks again,
    Brian

  6. bholub says:

    I was able to find a real workaround by changing my exec’s to target c:/php/php.exe and adding c:/php/phpdoc to the beginning of the arg line…. not very elegant, but it works. If anyone has a real solution I’d appreciate it. Once again, sorry for the useless posts above.

  7. mgkimsal says:

    Hey bholub – sorry I wasn’t able to help, but I’m glad you at least have a workaround!

  8. Mariano Del Rosso says:

    Hello, I’m from Argentina, sorry for my English.

    if you’re working with windows change the path variable in the environment variables. (My Computer> Properties> Advanced> Environnement Variables.
    Add paths to the executable files for php, phpdoc, pear, phunit, etc.

    Restart the cruisecontrol service and use phpdoc.bat insted of phpdoc into the executable attribute.

    Example:

    byee

Leave a Reply