static function main($argv) {
if (empty($argv[1])) {
echo "summary: Compares the output of different test runs\n";
- echo "usage: phpunit-compare [--phpunit-json|--jenkins-xml] <file1> <file2>...\n";
+ echo "usage: phpunit-compare [--out=txt|csv] [--phpunit-json|--jenkins-xml] <file1> <file2>...\n";
exit(1);
}
$parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults');
+ $printerType = 'txt';
$suites = array(); // array('file' => string, 'results' => array)
for ($i = 1; $i < count($argv); $i++) {
switch ($argv[$i]) {
case '--jenkins-xml':
$parser = array('\Civi\CiUtil\JenkinsParser', 'parseXmlResults');
break;
+ case '--out=txt':
+ $printerType = 'txt';
+ break;
+ case '--out=csv':
+ $printerType = 'csv';
+ break;
default:
$suites[] = array(
'file' => $argv[$i],
}
sort($tests);
- $printer = new \Civi\CiUtil\ComparisonPrinter(\Civi\CiUtil\Arrays::collect($suites, 'file'));
+ if ($printerType == 'csv') {
+ $printer = new \Civi\CiUtil\CsvPrinter('php://stdout', \Civi\CiUtil\Arrays::collect($suites, 'file'));
+ } else {
+ $printer = new \Civi\CiUtil\ComparisonPrinter(\Civi\CiUtil\Arrays::collect($suites, 'file'));
+ }
foreach ($tests as $test) {
$values = array();
foreach ($suites as $suite) {
--- /dev/null
+<?php
+namespace Civi\CiUtil;
+
+class CsvPrinter {
+ var $file;
+ var $headers;
+ var $hasHeader = FALSE;
+
+ function __construct($file, $headers) {
+ $this->file = fopen($file, "w");
+ $this->headers = $headers;
+ }
+
+ function printHeader() {
+ if ($this->hasHeader) {
+ return;
+ }
+
+ $headers = array_values($this->headers);
+ array_unshift($headers, 'TEST NAME');
+ fputcsv($this->file, $headers);
+
+ $this->hasHeader = TRUE;
+ }
+
+ function printRow($test, $values) {
+ $this->printHeader();
+ $row = $values;
+ array_unshift($row, $test);
+ fputcsv($this->file, $row);
+ }
+}
\ No newline at end of file