This is the first release of the phpUnderControl tool. This tool aims to take the first steps with CruiseControl and PHP as easy as possible. phpUnderControl 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, as you can see in the following screenshot.
Getting started
Now let's take a look how to start with CruiseControl and phpUnderControl. The first things you need is a Java environment and a working installation of CruiseControl. I assume that Java is already installed and so I will not cover this topic here, but I suggest to use an original Java version from SUN instead of some versions bundled with linux distributions, because in combination with compiz or beryl the metrics view can be broken.
Getting a working CruiseControl installation is a simple task. Just download one of the provided zip archives, unpack the contents and start the application. Because this initial release of phpUnderControl is only tested with CruiseControl 2.7, I suggest to use this version for the moment. You can download this version, if you click the following link:
cruisecontrol-bin-2.7.zip
When the download has finished, just unzip the archive.
unzip cruisecontrol-bin-2.7.zip -d /opt/
For a detailed installation description how to install CruiseControl and how to configure it with PHPUnit I recommend an excellent article by Sebastian Nohn and the Continuous Integration chapter from the PHPUnit Pocket Guide written by Sebastian Bergmann.
Now, that you have a working CruiseControl, download the phpUnderControl tool from the following url and unpack the archive:
Small bugfix release, I left some system() calls in the source code.
phpUnderControl-0.1.1.tar.gz
phpUnderControl-0.1.0.tar.gz
Now, you need to change to the phpUnderControl/bin directory and execute the following command to install the required files. All files that the command line tool modifies, are backed up with the file extension .orig.
[mapi@frodo bin]$ ./phpuc.php install /opt/cruisecontrol-bin-2.7
Modifying CruiseControl files.
File "main.jsp" modified.
File "metrics.jsp" modified.
File "xsl/buildresults.xsl" modified.
Installing new CruiseControl files.
File "phpcs.jsp" installed.
File "phpunit-pmd.jsp" installed.
File "xsl/phpcs.xsl" installed.
File "xsl/phpcs-details.xsl" installed.
File "xsl/phpdoc.xsl" installed.
File "xsl/phphelper.xsl" installed.
File "xsl/phpunit-pmd.xsl" installed.
File "xsl/phpunit-pmd-details.xsl" installed.
Modifying CruiseControl stylesheet.
Creating backup of "css/cruisecontrol.css" as "css/cruisecontrol.css.orig".
All you need now is an application with that CruiseControl can work. phpUnderControl comes with a little example application which can be installed with the following command. This example doesn't require any version control system installation. Instead it uses a special tag, that CruiseControl provides.
[mapi@frodo bin]$ ./phpuc.php example -t ant /opt/cruisecontrol-bin-2.7
Creating required project directories.
1. Creating CruiseControl project dir "projects/php-under-control".
2. Creating Project input dir "php-under-control/source".
3. Creating Project source dir "php-under-control/source/src".
4. Creating Project test dir "php-under-control/source/tests".
5. Creating Project build dir "php-under-control/build".
6. Creating Project log dir "php-under-control/build/logs"
7. Creating API documentation dir "/tmp/php-under-control/api"
8. Creating Coverage dir "/tmp/php-under-control/coverage"
Creating example files.
Creating file "php-under-control/source/src/Math.php".
Creating file "php-under-control/source/tests/MathTest.php".
Creating project build file "php-under-control/build.xml".
Preparing CruiseControl "/opt/cruisecontrol-bin-2.7/config.xml.
1. Loading "config.xml" data.
2. Backup original "config.xml" as "config.xml.orig".
3. Creating new project configuration.
Now change to the /opt/cruisecontrol-bin-2.7 directory and execute the cruisecontrol.sh or cruisecontrol.bat script to start CruiseControl. If you open your browser with this url http://127.0.0.1:8080/buildresults/php-under-control you will see something similar to the next screenshot.
PHPUnit features integrated
As mentioned in a previous post Sebastian Bergmann integrated support for Software Metrics and PMD in the PHPUnit 3.2 branch. Because he has used the original PMD format, the generated output was usable for CruiseControl without any modifications. Additionaly he integrated a third party contribution for Copy & Paste Detection that makes finding duplicate code fragments much easier. To show the results of this new report type the phpUnderControl tool provides modified versions of the original files pmd.xsl, pmd-details.xsl and metrics.jsp that can visualize the new records.
PHP_CodeSniffer integration
The PEAR package PHP_CodeSniffer makes us PHP developers a present. With this handy tool coding guildline checks have become a really simple task. As a positive reaction on an other article Greg Sherwood, the lead developer of PHP_CodeSniffer, added support for the Checkstyle format to this package. Cool :-), with the upcoming 1.0.0RC3 release of PHP_CodeSniffer this package will work together with CruiseControl without any changes. The following screenshot shows the PHP_CodeSniffer result for the phpUnderControl example. Please note, all these errors are provoked and not the result of bad coding
PLEASE NOTE: The current version 1.0.0RC2 has a small bug in the checkstyle output that causes CruiseControl to fail with the Checkstyle report. I hope this will be fixed in the RC3 release, but if you cannot wait just change line 720 in <pear-install>/PHP/CodeSniffer.php from
echo ' line="'.$line.' "column="'.$column.'"';
to
echo ' line="'.$line.'" column="'.$column.'"';
or you apply the following patch to <pear-install>/PHP/CodeSniffer.php
Index: CodeSniffer.php
===================================================================
RCS file: /repository/pear/PHP_CodeSniffer/CodeSniffer.php,v
retrieving revision 1.55
diff -r1.55 CodeSniffer.php
720c720
< echo ' line="'.$line.' "column="'.$column.'"';
---
> echo ' line="'.$line.'" column="'.$column.'"';
or you modify the build.xml file and use the XSL-Stylesheet from my previous post.
phpDocumentor integration
During the last user group meeting, while all others were hacking on some stuff. I thought this small javadoc legend in the "Coding violations" view must be fillable with the results of the standard PHP documentation tool phpDocumentor. The current integration is based on text matching onto the command line output of the phpdoc script which is not a perfect solution. For a future release of phpUnderControl there will be a custom implementation of the output converter that will process the documentation errors and warnings.
Finally
I hope this post and the phpUnderControl tool helps someone and was interesting for some of the readers. The current version is only tested under linux which means that I cannot say anything about windows, so I would be delighted if someone provides windows phpuc.bat or phpuc.cmd file.
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 in
Tracked: Nov 19, 11:45