Entries tagged as php_codesnifferRelated tags checkstyle continuous integration cruisecontrol cyclomatic complexity design quality npath complexity php phpunit php_depend pmd quality assurance software metrics ant arbit bug fix css customization dashboard ezcomponents java server pages layout lint php5 phpdoc phpundercontrol release announcement sebastian marek testing tutorial cli usability book changes company conference consulting crazy dortmund elephpant ext/filter fabien potencier fun hamburg logger phpbbq phpmd phpt phpug phpugdo pirum quality software architecture software design static code analysis static_reflection support talks thinkpad tools training unconference unit test xml xpath zce zend certified engineer annotations cbo class interface size coupling between objects optimization overview pyramid performance rule setSunday, November 18. 2007First release of phpUnderControlThis 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 startedNow 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: 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. 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 integratedAs 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 integrationDuring 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. FinallyI 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.
Posted by Manuel Pichler
in php, phpugdo, phpundercontrol, planet-php
at
16:41
| Comments (5)
| Trackback (1)
Saturday, October 27. 2007More QA with CruiseControl and PHP_CodeSnifferI am using CruiseControl for some time now, to run all Unit Tests for a project continuous after each commit. Since Sebastian Bergmann started the development of PHPUnit 3.2 he added support for software metrics and PMD to PHPUnit, that give you further informations about the quality of your source code. These two features are really well integrated into CruiseControl, the only thing you need to do is to comment out the following lines in the main.jsp file. <%-- <cruisecontrol:tab name="pmd" label="PMD"> <%@ include file="pmd.jsp" %> </cruisecontrol:tab> --%> The next thing that is important for each project is the coding standard of a project, a company or at least a single person. Java has a nice tool called Checkstyle that checks all your code against a defined set of rules. I knew this tool really well from my diploma thesis, because I used Checkstyle to check the complete code against the Sun coding standards. Checkstyle is also really good integrated into CruiseControl, so that it checks on each build that your code meets the coding standards.
So what can a PHP developer do, to achieve the same support? This question is answered fast! There is a nice PEAR package that does nearly the same job as Checkstyle. The name of this package is PHP_CodeSniffer. This PEAR package provides a variety of pre defined coding standards like PEAR, ZEND etc., a small cli script <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" omit-xml-declaration="no" indent="yes" /> <xsl:template match="/"> <checkstyle> <xsl:apply-templates select="phpcs/*" /> </checkstyle> </xsl:template> <xsl:template match="file"> <file> <xsl:attribute name="name"> <xsl:value-of select="@name" /> </xsl:attribute> <xsl:for-each select="child::*"> <xsl:call-template name="entry" /> </xsl:for-each> </file> </xsl:template> <xsl:template name="entry"> <error> <xsl:attribute name="line"> <xsl:value-of select="@line" /> </xsl:attribute> <xsl:attribute name="severity"> <xsl:value-of select="local-name()" /> </xsl:attribute> <xsl:attribute name="message"> <xsl:value-of select="text()" /> </xsl:attribute> </error> </xsl:template> </xsl:stylesheet>
You have to add the following lines to your ant <?xml version="1.0" encoding="UTF-8"?> <project name="mapi-xplib-de" default="build" basedir="."> ... <target name="checkstyle"> <exec executable="phpcs" output="${basedir}/build/logs/codesniffer.pcs" dir="${basedir}/source"> <arg line="--report=xml --standard=MapiSource --ignore=src/autoload src/" /> </exec> <exec executable="xsltproc" output="${basedir}/build/logs/checkstyle.xml" dir="${basedir}/build/logs"> <arg line="${checkstyle.xslt} ${basedir}/build/logs/codesniffer.pcs" /> </exec> </target> <target name="build" depends="checkout,checkstyle,test" /> ... </project>
PLEASE NOTE I know that ant supports xsl transformation without external exec commands but it doesn't work with my current gcj installation.
Posted by Manuel Pichler
in php, phpugdo
at
19:03
| Comment (1)
| Trackback (1)
Defined tags for this entry: checkstyle, continuous integration, cruisecontrol, php, php_codesniffer, quality assurance
(Page 1 of 1, totaling 2 entries)
|
ProjectsFurther stuffCategories |

