static function main($argv) {
if (empty($argv[1])) {
echo "summary: Compares the output of different test runs\n";
- echo "usage: phpunit-compare <json-file1> [<json-file2>...]\n";
+ echo "usage: phpunit-compare [--phpunit-json|--jenkins-xml] <file1> <file2>...\n";
exit(1);
}
-
+ $parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults');
$suites = array(); // array('file' => string, 'results' => array)
for ($i = 1; $i < count($argv); $i++) {
- $suites[$i] = array(
- 'file' => $argv[$i],
- 'results' => \Civi\CiUtil\PHPUnitParser::parseJsonResults(file_get_contents($argv[$i]))
- );
+ switch ($argv[$i]) {
+ case '--phpunit-json':
+ $parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults');
+ break;
+ case '--jenkins-xml':
+ $parser = array('\Civi\CiUtil\JenkinsParser', 'parseXmlResults');
+ break;
+ default:
+ $suites[] = array(
+ 'file' => $argv[$i],
+ 'results' => call_user_func($parser, file_get_contents($argv[$i])),
+ );
+ }
}
$tests = array(); // array(string $name)
- foreach ($suites as $suiteName => $suite) {
+ foreach ($suites as $suite) {
$tests = array_unique(array_merge(
$tests,
array_keys($suite['results'])
$printer = new \Civi\CiUtil\ComparisonPrinter(\Civi\CiUtil\Arrays::collect($suites, 'file'));
foreach ($tests as $test) {
$values = array();
- foreach ($suites as $suiteName => $suite) {
+ foreach ($suites as $suite) {
$values[] = isset($suite['results'][$test]) ? $suite['results'][$test] : 'MISSING';
}
--- /dev/null
+<?php
+namespace Civi\CiUtil;
+
+/**
+ * Parse Jenkins result files
+ */
+class JenkinsParser {
+ /**
+ * @param string $content xml data
+ * @return array (string $testName => string $status)
+ */
+ public static function parseXmlResults($content) {
+ $xml = simplexml_load_string($content);
+ $results = array();
+ foreach ($xml->suites as $suites) {
+ foreach ($suites->suite as $suite) {
+ foreach ($suite->cases as $cases) {
+ foreach ($cases->case as $case) {
+ $name = "{$case->className}::{$case->testName}";
+ if ($case->failedSince == 0) {
+ $results[$name] = 'pass';
+ }
+ else {
+ $results[$name] = 'fail';
+ }
+ }
+ }
+ }
+ }
+ return $results;
+ }
+}
\ No newline at end of file