Steven Scott
Steven Scott

Reputation: 11250

Running PHPUnit on Different OS's with differences in XML configuration file

Is it possible to have configuration differences in the PHPUnit XML file that are processed at runtime so as to configure settings based on platform of execution? For instance, use Color on Ubuntu, but not in Windows.

To explain:

I have different development platforms being used, and want to ensure that our code works for web servers on either platform. Also, the tools we use are on different platforms. For instance, the inhouse backend servers for the Developers (PHPUnit, PHPDocs, Wiki, other tools) are on a Ubuntu computer. The developers actively use Windows based PCs.

When a developer changes code, we want them to be able to test that their code works before checking it into our repository. Therefore, they run PHPUnit, PHP_CodeSniffer, PHPMD and PHPDocs on their local machine to see things are okay to commit.

The main system then, will see the code committed, and will re-run these tests in conjunction with everyone elses code changes on the Ubuntu machine, update the company wide pages with test results, code coverage, etc... These tests may even be run on different computers with different OS/Language configurations. Web Browser testing via Selenium is also started at this point, again, across many different Web Server/OS/Browser versions.

As we introduce new tools, different projects, etc..., the XML files are changing with exclude files, test suite configurations etc... As such, we keep this file in the source tree to ensure the developers have the latest settings when running their tests.

I want to be able to configure some settings differently by platform (that would work for all our combinations as I could set whatever variable is being used) without having to have different files that are then copied after the source to ensure the changes are received.

Is this reasonable, or would using something like Jenkins help me avoid this issue? However, I am trying to keep the tools on the Windows PC as basic as possible to facilitate letting the developers run them quickly, or they will ignore the step.

Upvotes: 2

Views: 205

Answers (1)

Josh Woodcock
Josh Woodcock

Reputation: 2783

This answer turned to be longer than expected but it is appropriate. The quick answer is to just build different config files. phpunitwindows7.xml

phpunitubuntu.xml

phpunitmacosx.xml

etc...

But I think your problem is that there are so many different configs that doing this would be a lot of maintenance so what I would do first is build an object with the settings that I wanted. load a base phpunit.xml into a SimpleXML object

$sxe = simplexml_load_file('phpunit.xml);
// Modify a node
$sxe->phpunit = '<tessuites....>';

// You can access an element's attribute just like this :
$attribute = $sxe->phpunit->attributes()->$att;

$sxe->phpunit->attributes()->$verbose = $phpunitSettings->verbose;

// Saving the whole modified XML to a new filename
$sxe->asXml('windows7-cookie-cutter-phpunit.xml');

Each developer would have their build configs set to whichever phpunit config file appropriate based on their os / project etc.

Jenkins will of course help you do this because you could run this script in your Ant build file to update these phpunit config files before phpunit runs instead of running it manually.

Another thing you might do is to use the

<?php 
    header ("Content-Type:text/xml");
?>

to show a dynamic file like this

<phpunit setting="<?php echo $setting; ?>"

><!-- yada yada-->
</phpunit>

The dynamic file would still have to be accessed by the php script but could be easily done with cUrl to get the content exe:

http://yoursite.com/apps/phpunit-config.php?os=windows7&project=cookiecutterblog

Also if you have jenkins installed on the developer machines it can be set to run every hour/day with Poll SCM so it wouldn't matter if they wanted to use it or not, it would still be used without them even knowing it!

enter image description here

If you are using the MakeGood extension in eclipse you can preload the script to update the phpunit config file.

make good

Which can be loaded and easily run in the IDE every time a file is edited and then saved enter image description here

Here's a MakeGood IDE setup tutorial which I put together.

I'm not sure it would be possible to be easier for the devs since they wouldn't do anything at all...

Upvotes: 2

Related Questions