Commit | Line | Data |
---|---|---|
f03dc6b0 TO |
1 | <?php |
2 | namespace Civi\CiUtil\Command; | |
3 | ||
7fe37828 EM |
4 | /** |
5 | * Class CompareCommand | |
6 | * | |
7 | * @package Civi\CiUtil\Command | |
8 | */ | |
f03dc6b0 | 9 | class CompareCommand { |
7fe37828 EM |
10 | /** |
11 | * @param $argv | |
12 | */ | |
00be9182 | 13 | public static function main($argv) { |
f03dc6b0 TO |
14 | if (empty($argv[1])) { |
15 | echo "summary: Compares the output of different test runs\n"; | |
dc34d722 | 16 | echo "usage: phpunit-compare [--out=txt|csv] [--phpunit-json|--jenkins-xml] <file1> <file2>...\n"; |
f03dc6b0 TO |
17 | exit(1); |
18 | } | |
19 | ||
3433cc3b | 20 | $parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults'); |
dc34d722 | 21 | $printerType = 'txt'; |
f03dc6b0 TO |
22 | $suites = array(); // array('file' => string, 'results' => array) |
23 | for ($i = 1; $i < count($argv); $i++) { | |
3433cc3b TO |
24 | switch ($argv[$i]) { |
25 | case '--phpunit-json': | |
26 | $parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults'); | |
27 | break; | |
ea100cb5 | 28 | |
3433cc3b TO |
29 | case '--jenkins-xml': |
30 | $parser = array('\Civi\CiUtil\JenkinsParser', 'parseXmlResults'); | |
31 | break; | |
ea100cb5 | 32 | |
1ea1fd20 TO |
33 | case '--csv': |
34 | $parser = array('\Civi\CiUtil\CSVParser', 'parseResults'); | |
35 | break; | |
ea100cb5 | 36 | |
dc34d722 TO |
37 | case '--out=txt': |
38 | $printerType = 'txt'; | |
39 | break; | |
ea100cb5 | 40 | |
dc34d722 TO |
41 | case '--out=csv': |
42 | $printerType = 'csv'; | |
43 | break; | |
ea100cb5 | 44 | |
3433cc3b TO |
45 | default: |
46 | $suites[] = array( | |
47 | 'file' => $argv[$i], | |
48 | 'results' => call_user_func($parser, file_get_contents($argv[$i])), | |
49 | ); | |
50 | } | |
f03dc6b0 TO |
51 | } |
52 | ||
53 | $tests = array(); // array(string $name) | |
3433cc3b | 54 | foreach ($suites as $suite) { |
f03dc6b0 TO |
55 | $tests = array_unique(array_merge( |
56 | $tests, | |
57 | array_keys($suite['results']) | |
58 | )); | |
59 | } | |
60 | sort($tests); | |
61 | ||
dc34d722 TO |
62 | if ($printerType == 'csv') { |
63 | $printer = new \Civi\CiUtil\CsvPrinter('php://stdout', \Civi\CiUtil\Arrays::collect($suites, 'file')); | |
0db6c3e1 TO |
64 | } |
65 | else { | |
dc34d722 TO |
66 | $printer = new \Civi\CiUtil\ComparisonPrinter(\Civi\CiUtil\Arrays::collect($suites, 'file')); |
67 | } | |
f03dc6b0 TO |
68 | foreach ($tests as $test) { |
69 | $values = array(); | |
3433cc3b | 70 | foreach ($suites as $suite) { |
f03dc6b0 TO |
71 | $values[] = isset($suite['results'][$test]) ? $suite['results'][$test] : 'MISSING'; |
72 | } | |
73 | ||
74 | if (count(array_unique($values)) > 1) { | |
75 | $printer->printRow($test, $values); | |
76 | } | |
77 | } | |
78 | } | |
96025800 | 79 | |
f03dc6b0 | 80 | } |