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