2 namespace Civi\CiUtil\Command
;
4 class AntagonistCommand
{
5 static function main($argv) {
6 if (count($argv) != 3) {
7 print "usage: {$argv[0]} <TargetTest::testFunc> </path/to/suite>\n";
10 list ($program, $target, $suite) = $argv;
12 $candidateTests = \Civi\CiUtil\PHPUnitScanner
::findTestsByPath(array($suite));
13 // $candidateTests = array(
14 // array('class' => 'CRM_Core_RegionTest', 'method' => 'testBlank'),
15 // array('class' => 'CRM_Core_RegionTest', 'method' => 'testDefault'),
16 // array('class' => 'CRM_Core_RegionTest', 'method' => 'testOverride'),
17 // array('class' => 'CRM_Core_RegionTest', 'method' => 'testAllTypes'),
19 $antagonist = self
::findAntagonist($target, $candidateTests);
21 print_r(array('found an antagonist' => $antagonist));
24 print_r(array('found no antagonists'));
29 * @param string $target e.g. "MyTest::testFoo"
30 * @param array $candidateTests list of strings (e.g. "MyTest::testFoo")
31 * @return array|null array contains keys:
36 * - expectedResults: array
37 * - actualResults: array
39 static function findAntagonist($target, $candidateTests) {
40 //$phpUnit = new \Civi\CiUtil\EnvTestRunner('./scripts/phpunit', 'EnvTests');
41 $phpUnit = new \Civi\CiUtil\
EnvTestRunner('phpunit', 'tests/phpunit/EnvTests.php');
42 $expectedResults = $phpUnit->run(array($target));
43 print_r(array('$expectedResults' => $expectedResults));
45 foreach ($candidateTests as $candidateTest) {
46 $candidateTestName = $candidateTest['class'] . '::' . $candidateTest['method'];
47 if ($candidateTestName == $target) {
50 $actualResults = $phpUnit->run(array(
54 print_r(array('$actualResults' => $actualResults));
55 foreach ($expectedResults as $testName => $expectedResult) {
56 if ($actualResults[$testName] != $expectedResult) {
58 'antagonist' => $candidateTest,
59 'expectedResults' => $expectedResults,
60 'actualResults' => $actualResults,