Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script that merges multiple PHPUnit XML logfiles (JUnit XML) into one PHPUnit XML logfile.
#!/usr/bin/env php
<?php
require 'SebastianBergmann/FinderFacade/autoload.php';
require 'TheSeer/fDOMDocument/autoload.php';
use SebastianBergmann\FinderFacade\FinderFacade;
use TheSeer\fDOM\fDOMDocument;
$input = new FinderFacade(array($argv[1]), array(), array('*.xml'));
$output = $argv[2];
$outXml = new fDOMDocument;
$outXml->formatOutput = TRUE;
$outTestSuites = $outXml->createElement('testsuites');
$outXml->appendChild($outTestSuites);
$outTestSuite = $outXml->createElement('testsuite');
$outTestSuites->appendChild($outTestSuite);
$tests = 0;
$assertions = 0;
$failures = 0;
$errors = 0;
$time = 0;
foreach ($input->findFiles() as $file) {
$inXml = new fDOMDocument;
$inXml->load($file);
foreach ($inXml->getElementsByTagName('testsuite') as $inElement) {
$outElement = $outXml->importNode($inElement, TRUE);
$outTestSuite->appendChild($outElement);
$tests += $inElement->getAttribute('tests');
$assertions += $inElement->getAttribute('assertions');
$failures += $inElement->getAttribute('failures');
$errors += $inElement->getAttribute('errors');
$time += $inElement->getAttribute('time');
}
}
$outTestSuite->setAttribute('tests', $tests);
$outTestSuite->setAttribute('assertions', $assertions);
$outTestSuite->setAttribute('failures', $failures);
$outTestSuite->setAttribute('errors', $errors);
$outTestSuite->setAttribute('time', $time);
$outXml->save($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.