test.ical.ly | getting the web by the balls

May/10

4

Running PHPUnit tests for your symfony plugin in Hudson

PHPUnit-testing-symfony-in-HudsonYesterday 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“.

hudson-new-job

Hudson dialog: 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.

Hudson dialog: Job Configuration

Hudson dialog: Job Configuration

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.

Hudson dialog: Job Configuration

Hudson dialog: Job Configuration

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.

Hudson dialog: Job Configuration

Hudson dialog: Job Configuration

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.

Hudson dialog: Job Configuration

Hudson dialog: Job Configuration

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.

hudson-job-configuration-5

Hudson dialog: Job Configuration

Then we enter the location of the result XML generated by the previous build step.

Hudson dialog: Job Configuration

Hudson dialog: Job Configuration

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.

Hudson job page

Hudson job page

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:

Hudson: Successful first build

Hudson: Successful first build

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. ;)

· · · · · · · · · ·



  • Pingback: Tweets that mention • Running PHPUnit tests for your symfony plugin in Hudson | test.ical.ly -- Topsy.com

  • Pingback: • Running PHPUnit tests for your symfony plugin in Hudson | test … | Programming Blog Imagik.org

  • Stu

    Nice article Christian :)

  • http://test.ical.ly Christian

    @Stu Cheers mate! ;)

  • http://daraff.ch Ralph Meier

    As a CI beginner I have decided to setup Hudson (and not phpUnderControl). Good, that you, PHPGangsta and PHPMonkeys have released some good tutorials. This will save me a lot of time :-)

  • http://www.robo47.net robo47

    For setups where you have many builds every day and/or many/big dependencies, creating local backups of dependencies (here symfony for example) can save a lot of build-time and traffic (for you own server and the repository-server [if not same]) each build.
    A local file-copy or even symlinking! (shared libs should be non-writeable by hudson-user) will in most cases be much faster than a svn-checkout via http.

    For svn the “mirrors” can be git/mercury clones and be updated via cron and fetched by hudson too or copied via the build-script, so keeping them up2date is easier and needs less space.

    I for example have some code with many dependencies and some bigger ones (Zend Framework, Doctrine, ezComponents, HTMLPurifier, …).

    I always build against fixed versions defined in my build-script-config and have one big git-repository, maintained by hand shared across development/test/production-system which contains all versions of frameworks and libs I use/test in different projects. I use that repository on my server (production) and test/build/development-environments, so i can really create builds “everywhere” even without the CI-Server or locally before I push my commits to the main-repository.

    And since git offers really nice compression and only has one blob for multiple files with the same content, many versions of a lib/framework are “cheap” to exchange between the systems, it is very fast too and does not need much bandwidth. Currently ~140k files, 1.3 gb data resulting in an only about 70mb big repository (after git gc).

    Using an extra repository for the CI-Server with a dvcs (git, mercurial, bazaar, [works with svn-mainserver and git-svn for local work and ci-server too]) allows an easy “git/mercurial/bazaar push ciserver” to send the local commits only to the ci-server and “build” without making the main-repository dirty with code [I used that for a long time because my CI-Server was a lot faster than my notebook, especially when running phpunit with xdebug and i could work while the build was running].

    With the build-script and the config I am able to easily build everywhere (if i am offline but want all reports/data [code-coverage, copy-and-paste-detection, for optimizing, etc]) and against different versions very easy. Downloading all the dependencies locally each time would not be possible as long as i am offline and even if not, downloading them for each build would take very long on my slow 2mbit-connection at home.

    For everybody who uses ant together with hudson, Sebastian Bergmann has an ant-build.xml for usage with hudson including a template, including phpunit, phpmd, phpcpd, codesniffer and some more:

    http://github.com/sebastianbergmann/php-hudson-template

    btw, hudson allows cron-like polling-intervalls:
    */15 * * * *

    looks a bit more "all 15 minutes"-like for me :)

  • marek

    wrong first link :)

  • http://test.ical.ly Christian

    @Marek wow it took some time until someone noticed. ;)
    corrected this.

<<

>>

Theme Design by devolux.nh2.me