In a previous post, I described how to setup Hudson with Phing and PHPUnit for a simple PHP build process.
Adding PHP CodeSniffer to Build Results
Now let's expand on this a bit by adding PHP CodeSniffer (PHPCS).
First, assuming you're still working on Ubuntu, install PHPCS :
$ sudo pear install PHP_CodeSniffer
Add the Checkstyle to Hudson (Manage Hudson => Manage Plugins => Available).
In Hudson, go back to your project, and add hit 'Configure'. Check 'Publish Checkstyle analysis results' and enter this in the results box : build/start_page/reports/checkstyle.xml
Add the following to your build.xml file :
<!-- PHP CodeSniffer --> <exec command="phpcs --standard=ZEND --report=checkstyle ${ws}/src/ > ${builddir}/reports/checkstyle.xml" escape="false" />
Hit 'Build Now' in Hudson and you should see a generated Code Sniffer report with nice HTML reporting.
Adding Duplicate Code Checking to Build Results
This describes how to use the PMD (Project Mess Detection) which was added in PHPUnit 3.2. However, PHPUnit will remove this in PHPUnit 3.5, so this may not be that useful.
First, you will need to install the phpize and the Xdebug extension with :
$ sudo aptitude install php5-dev $ sudo pecl install xdebug (You should add "extension=xdebug.so" to php.ini)
Add the following to the PHPUnit task of your build.xml :
--log-pmd ${builddir}/reports/phpunit.pmd.xml
In Hudson, in your project configuration, add the following to 'Publish duplicate code analysis results' :
build/start_page/reports/phpunit.pmd.xml
Adding Clover Test Coverage Reports
Add the following to your build.xml (and commit to Git) :
--coverage-clover ${builddir}/reports/coverage/clover.xml
In Hudson, in your project configuration, add the following to 'Publish Clover Coverage Report' :
build/start_page/reports/coverage/
Adding PHP Depend Reporting
$ sudo pear channel-discover pear.pdepend.org $ pear install pdepend/PHP_Depend-beta
Add the following to build.xml and commit to Git. I had to use the '--bad-documentation' for this simple project, otherwise I didn't get any output.
<!-- PHP dependency checker --> <exec command="pdepend --bad-documentation --jdepend-xml=${builddir}/reports/jdepend.xml ${ws}/src" escape="false" />
In Hudson, in your project configuration, add the following to 'Report JDepend' :
build/start_page/reports/jdepend.xml
Adding PhpDocumentor Output
First, install PhpDocumentor if needed :
$ sudo pear install PhpDocumentor
Add the following to your build.xml :
<!-- PHP API Documentation --> <phpdoc title="API Documentation" destdir="${builddir}/apidocs" sourcecode="yes" defaultpackagename="StartPage" output="HTML:Smarty:PHP"> <fileset dir="."> <include name="*/*.php" /> </fileset> </phpdoc>
In Hudson, setup the following :
Publish Javadoc
Javadoc directory = build/start_page/apidocs/
Retain javadoc for each successful build = false
Adding Copy Paste Detector Reporting
Install CPD :
$ sudo pear install phpunit/phpcpd