From: Tim Otten Date: Tue, 26 Aug 2014 20:32:12 +0000 (-0700) Subject: phpunit-compare - Add support for reading results from Jenkins' XML files X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3433cc3b39cbf02ae211b2d3ad89027eaa4a2704;p=civicrm-core.git phpunit-compare - Add support for reading results from Jenkins' XML files --- diff --git a/Civi/CiUtil/Command/CompareCommand.php b/Civi/CiUtil/Command/CompareCommand.php index 494e909c09..44ee0dac2a 100644 --- a/Civi/CiUtil/Command/CompareCommand.php +++ b/Civi/CiUtil/Command/CompareCommand.php @@ -5,21 +5,30 @@ class CompareCommand { static function main($argv) { if (empty($argv[1])) { echo "summary: Compares the output of different test runs\n"; - echo "usage: phpunit-compare [...]\n"; + echo "usage: phpunit-compare [--phpunit-json|--jenkins-xml] ...\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']) @@ -30,7 +39,7 @@ class CompareCommand { $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'; } diff --git a/Civi/CiUtil/JenkinsParser.php b/Civi/CiUtil/JenkinsParser.php new file mode 100644 index 0000000000..900463b9db --- /dev/null +++ b/Civi/CiUtil/JenkinsParser.php @@ -0,0 +1,32 @@ + 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