forked from tarlepp/symfony-flex-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge-phpunit-xml.php
52 lines (42 loc) · 1.53 KB
/
merge-phpunit-xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env php
<?php
declare(strict_types = 1);
require __DIR__ . '/vendor/autoload.php';
use SebastianBergmann\FinderFacade\FinderFacade;
use TheSeer\fDOM\fDOMDocument;
$input = new FinderFacade([$argv[1]], [], ['*.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;
try {
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);
} catch (\Exception $exception) {
echo $exception->getMessage();
}