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



[Best practice] How to ship PHPUnit configuration

PHPUnit offers quite a lot options to be set as arguments on the commandline. However this is tedious when typing over and over again.

For this reason you can create an XML configuration file phpunit.xml that will automatically be used by the phpunit binary.

Now you may want to include this configuration file in your projects sourcecode to be used by all participating developers and your continuous integration server. But how?

Well, you could just commit the phpunit.xml to you repository right?

Well, yes. But then all developers who want to checkout and work on your project will have to use these settings or going through the trouble of maintaining local changes to the configuration or specifying a different one using the commandline.

No! Use phpunit.xml.dist instead.

Sebastian made me aware of this and he is right. If you provide a phpunit.xml.dist(ribution) instead then every developer can chose whether to use your configuration or his/her own.

It is also wise to ignore the real phpunit.xml for your repository using .gitignore or svn:ignore or similar. This way everybody can use the settings he/she wants without forcing them onto others.

How can my continuous integration server use the config?

Simple! the phpunit binary is clever enough to use any phpunit.xml.dist file if no phpunit.xml is available. :)

· · ·

  • http://daraff.ch Ralph Meier

    Hi Christian

    Thx for the tip!

    We use this method for other configuration files in SVN since 1 year in this way. But i didn’t know that PHPUnit is so clever and automatically takes the right file.

  • http://test.ical.ly Christian

    @Ralph I didn’t know either and only found out by mistake. :)

  • Pingback: 網站製作學習誌 » [Web] 連結分享

  • http://www.creatio.com.au Daniel

    Very handy, thanks for the tip! You must be looking forward to Symfony2 when all the phpunit integrations/conventions will be handled “natively”

  • http://test.ical.ly Christian

    @Daniel aren’t we just all? ;)

  • http://dev.esl.eu Frank

    Added information about this best practise to the sfPHPUnit2Plugin http://trac.symfony-project.org/changeset/30856. Thanks for this hint! :)



Theme Design by devolux.nh2.me