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