We are using Hudson now for several months as Continous Integration System. This short article describes how we have configured a hudson project for a symfony 1.4 project. I am assuming that the reader is already used to Hudson and knows how a normal project has to be configured.
PHPUnit is the test framework of our choice (surprise, surprise) and we are using the sfPHPUnit2Plugin for all our projects. If you do not now this plugin you may first read another post where the usage and features are described in detail.
All requirements in short:
- Hudson has to be installed
- Hudson plugin xUnit Plugin has to be installed
- the symfony project needs the sfPHPUnit2Plugin
- PHPUnit has to be installed on your test server
Ok, here the configuration steps of the hudson project:
1. Configure your project
Configure standard settings for a hudson project like source-code management settings or email notifications. Please check the official docs if you do not know how to handle this.
2. Add a shell build step
Building a symfony project in a test environment is pretty easy. With the help of some shell commands the project is completely configured and ready for testing. Those shell commands may be entered in the build step section of the hudson project. Defining the correct commands is the main part during the configuration process.
Our configuration looks like this:
php symfony cc
php symfony phpunit:test-all --configuration --options="--log-junit=build/testresult_$BUILD_NUMBER.xml"
ln -s -f testresult_$BUILD_NUMBER.xml currentTestResult.xml
- Jump in the project root of the project
- Install the project on the test server with the help of a internal shell script. This step includes for example the generation of the databases.yml.
- Clear the symfony cache (always a good choice)
- Run all PHPUnit tests including unit and functional tests. The test result is written in a jUnit compatible logfile (needed for the xUnit Plugin).
- Jump in the build directory, which is internally used by Hudson
- Symlink the latest testresult
3. Configure Post-Build-Action
After the xUnit Plugin is installed correctly, an additional PHPUnit Pattern field should be displayed in the post build action section. In this field has to be entered:
The options “Fail the build if test results were not updated this run” and “Delete temporary JUnit file” should be both checked.
The xUnit Plugin takes the currentTestResult.xml file, which was previously created with the help of the sfPHPUnit2Plugin and analyzes it. When everything works fine, you should be able to review the created test reports.
Here some screenshots how this result could look like.
Trend graph of the test results: