Running PHPUnit tests for your symfony plugin in Hudson
Yesterday I wrote about setting up a symfony plugin project in phpUnderControl. However so far I’ve been using Hudson as my Continuous Integration server. So before comparing the two I will explain how to achieve yesterdays setup using Hudson.I assume that you have a running Hudson installation ready.
Hudson is – as you will notice – a web dialog driven tool. You can of course edit the underlying configuration files (mostly XML) but I never experienced the need as the web interface is just as powerful.
Creating the project
In Hudson projects are called jobs. You create one by clicking on “New Job“.
What we want is a free-style software project.
This will directly lead us to the Job Configuration dialog.
Checking out the sources
In the Source Code Management section of the Job Configuration dialog we select Subversion for our version control system (There is a Git plugin for Hudson available) and configure the three sources for symfony, sfImageTransformPlugin and sfImageTransformExtraPlugin.
This is self explaining really.
Preparing the build
Next we want the project to be build whenever there is a commit to one of the sources.
The syntax for the schedule is cronjob like. In this example Subversion will be polled every 15 minutes.
Running the tests
Now we have to configure everything for Hudson to know how to run the PHPUnit tests. For this we need to add a build step.
There are several ways to do this, some are build-in such as using ant scripts while some require a plugin like using a phing script.
I found it easiest to use a shell command. For this you have to select Execute shell from the dropdown.
export SYMFONY=$WORKSPACE/symfony mkdir -p $WORKSPACE/logs rm -rf $WORKSPACE/logs/* cd $WORKSPACE/sfImageTransformExtraPlugin/ phpunit --log-xml=$WORKSPACE/logs/phpunit-results.xml test/sfImageTransformExtraPluginTests.php
As you can see this is a small bash script that sets the SYMFONY variable prepares a location for the PHPUnit report and runs the test suite.
The last thing we need to do is to tell Hudson what to do with the test results.
For this we add a Post-build Action and select PHPUnit.
Then we enter the location of the result XML generated by the previous build step.
For this last step you will need the xUnit Plugin installed.
If you don’t have xUnit Plugin installed already you can save your settings now and edit them later (browse to your Job and click on Configure).
Now save the dialog and you will be presented with your Jobs webpage.
Now click on Build Now to start the first build. This might take a while as the first checkout of symfony is quite big.
The successful build should look like this:
Now you can of course start adding more features such as pDepend, Cloverage reports, Mess Detection, Copy and Paste Detection and many more but for this post we’re done.