Commit | Line | Data |
---|---|---|
f03dc6b0 TO |
1 | <?php |
2 | namespace Civi\CiUtil\Command; | |
3 | ||
7fe37828 EM |
4 | /** |
5 | * Class AntagonistCommand | |
6 | * | |
7 | * @package Civi\CiUtil\Command | |
8 | */ | |
f03dc6b0 | 9 | class AntagonistCommand { |
7fe37828 EM |
10 | /** |
11 | * @param $argv | |
12 | */ | |
00be9182 | 13 | public static function main($argv) { |
f03dc6b0 TO |
14 | if (count($argv) != 3) { |
15 | print "usage: {$argv[0]} <TargetTest::testFunc> </path/to/suite>\n"; | |
16 | exit(1); | |
17 | } | |
18 | list ($program, $target, $suite) = $argv; | |
19 | ||
c64f69d9 | 20 | $candidateTests = \Civi\CiUtil\PHPUnitScanner::findTestsByPath([$suite]); |
bed98343 | 21 | // $candidateTests = array( |
22 | // array('class' => 'CRM_Core_RegionTest', 'method' => 'testBlank'), | |
23 | // array('class' => 'CRM_Core_RegionTest', 'method' => 'testDefault'), | |
24 | // array('class' => 'CRM_Core_RegionTest', 'method' => 'testOverride'), | |
25 | // array('class' => 'CRM_Core_RegionTest', 'method' => 'testAllTypes'), | |
26 | // ); | |
f03dc6b0 TO |
27 | $antagonist = self::findAntagonist($target, $candidateTests); |
28 | if ($antagonist) { | |
c64f69d9 | 29 | print_r(['found an antagonist' => $antagonist]); |
f03dc6b0 TO |
30 | } |
31 | else { | |
c64f69d9 | 32 | print_r(['found no antagonists']); |
f03dc6b0 TO |
33 | } |
34 | } | |
35 | ||
36 | /** | |
04855556 TO |
37 | * @param string $target |
38 | * E.g. "MyTest::testFoo". | |
39 | * @param array $candidateTests | |
40 | * List of strings (e.g. "MyTest::testFoo"). | |
72b3a70c CW |
41 | * @return array|null |
42 | * array contains keys: | |
43 | * - antagonist: array | |
44 | * - file: string | |
45 | * - class: string | |
46 | * - method: string | |
47 | * - expectedResults: array | |
48 | * - actualResults: array | |
f03dc6b0 | 49 | */ |
00be9182 | 50 | public static function findAntagonist($target, $candidateTests) { |
f03dc6b0 TO |
51 | //$phpUnit = new \Civi\CiUtil\EnvTestRunner('./scripts/phpunit', 'EnvTests'); |
52 | $phpUnit = new \Civi\CiUtil\EnvTestRunner('phpunit', 'tests/phpunit/EnvTests.php'); | |
c64f69d9 CW |
53 | $expectedResults = $phpUnit->run([$target]); |
54 | print_r(['$expectedResults' => $expectedResults]); | |
f03dc6b0 TO |
55 | |
56 | foreach ($candidateTests as $candidateTest) { | |
57 | $candidateTestName = $candidateTest['class'] . '::' . $candidateTest['method']; | |
58 | if ($candidateTestName == $target) { | |
59 | continue; | |
60 | } | |
c64f69d9 | 61 | $actualResults = $phpUnit->run([ |
f03dc6b0 TO |
62 | $candidateTestName, |
63 | $target, | |
c64f69d9 CW |
64 | ]); |
65 | print_r(['$actualResults' => $actualResults]); | |
f03dc6b0 TO |
66 | foreach ($expectedResults as $testName => $expectedResult) { |
67 | if ($actualResults[$testName] != $expectedResult) { | |
c64f69d9 | 68 | return [ |
f03dc6b0 TO |
69 | 'antagonist' => $candidateTest, |
70 | 'expectedResults' => $expectedResults, | |
71 | 'actualResults' => $actualResults, | |
c64f69d9 | 72 | ]; |
f03dc6b0 TO |
73 | } |
74 | } | |
75 | } | |
76 | return NULL; | |
77 | } | |
96025800 | 78 | |
ef10e0b5 | 79 | } |