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 | ||
20 | $candidateTests = \Civi\CiUtil\PHPUnitScanner::findTestsByPath(array($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) { | |
29 | print_r(array('found an antagonist' => $antagonist)); | |
30 | } | |
31 | else { | |
32 | print_r(array('found no antagonists')); | |
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'); | |
53 | $expectedResults = $phpUnit->run(array($target)); | |
54 | print_r(array('$expectedResults' => $expectedResults)); | |
55 | ||
56 | foreach ($candidateTests as $candidateTest) { | |
57 | $candidateTestName = $candidateTest['class'] . '::' . $candidateTest['method']; | |
58 | if ($candidateTestName == $target) { | |
59 | continue; | |
60 | } | |
61 | $actualResults = $phpUnit->run(array( | |
62 | $candidateTestName, | |
63 | $target, | |
64 | )); | |
65 | print_r(array('$actualResults' => $actualResults)); | |
66 | foreach ($expectedResults as $testName => $expectedResult) { | |
67 | if ($actualResults[$testName] != $expectedResult) { | |
68 | return array( | |
69 | 'antagonist' => $candidateTest, | |
70 | 'expectedResults' => $expectedResults, | |
71 | 'actualResults' => $actualResults, | |
72 | ); | |
73 | } | |
74 | } | |
75 | } | |
76 | return NULL; | |
77 | } | |
96025800 | 78 | |
ef10e0b5 | 79 | } |