Skip to content

Instantly share code, notes, and snippets.

@unusorin
Last active August 29, 2015 14:20
Show Gist options
  • Save unusorin/6afd59809a62a68ebfdb to your computer and use it in GitHub Desktop.
Save unusorin/6afd59809a62a68ebfdb to your computer and use it in GitHub Desktop.
#!/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