First commit
This commit is contained in:
commit
c6e2478c40
13918 changed files with 2303184 additions and 0 deletions
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
namespace Civi\CiUtil\Command;
|
||||
|
||||
/**
|
||||
* Class AntagonistCommand
|
||||
*
|
||||
* @package Civi\CiUtil\Command
|
||||
*/
|
||||
class AntagonistCommand {
|
||||
/**
|
||||
* @param $argv
|
||||
*/
|
||||
public static function main($argv) {
|
||||
if (count($argv) != 3) {
|
||||
print "usage: {$argv[0]} <TargetTest::testFunc> </path/to/suite>\n";
|
||||
exit(1);
|
||||
}
|
||||
list ($program, $target, $suite) = $argv;
|
||||
|
||||
$candidateTests = \Civi\CiUtil\PHPUnitScanner::findTestsByPath(array($suite));
|
||||
// $candidateTests = array(
|
||||
// array('class' => 'CRM_Core_RegionTest', 'method' => 'testBlank'),
|
||||
// array('class' => 'CRM_Core_RegionTest', 'method' => 'testDefault'),
|
||||
// array('class' => 'CRM_Core_RegionTest', 'method' => 'testOverride'),
|
||||
// array('class' => 'CRM_Core_RegionTest', 'method' => 'testAllTypes'),
|
||||
// );
|
||||
$antagonist = self::findAntagonist($target, $candidateTests);
|
||||
if ($antagonist) {
|
||||
print_r(array('found an antagonist' => $antagonist));
|
||||
}
|
||||
else {
|
||||
print_r(array('found no antagonists'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $target
|
||||
* E.g. "MyTest::testFoo".
|
||||
* @param array $candidateTests
|
||||
* List of strings (e.g. "MyTest::testFoo").
|
||||
* @return array|null
|
||||
* array contains keys:
|
||||
* - antagonist: array
|
||||
* - file: string
|
||||
* - class: string
|
||||
* - method: string
|
||||
* - expectedResults: array
|
||||
* - actualResults: array
|
||||
*/
|
||||
public static function findAntagonist($target, $candidateTests) {
|
||||
//$phpUnit = new \Civi\CiUtil\EnvTestRunner('./scripts/phpunit', 'EnvTests');
|
||||
$phpUnit = new \Civi\CiUtil\EnvTestRunner('phpunit', 'tests/phpunit/EnvTests.php');
|
||||
$expectedResults = $phpUnit->run(array($target));
|
||||
print_r(array('$expectedResults' => $expectedResults));
|
||||
|
||||
foreach ($candidateTests as $candidateTest) {
|
||||
$candidateTestName = $candidateTest['class'] . '::' . $candidateTest['method'];
|
||||
if ($candidateTestName == $target) {
|
||||
continue;
|
||||
}
|
||||
$actualResults = $phpUnit->run(array(
|
||||
$candidateTestName,
|
||||
$target,
|
||||
));
|
||||
print_r(array('$actualResults' => $actualResults));
|
||||
foreach ($expectedResults as $testName => $expectedResult) {
|
||||
if ($actualResults[$testName] != $expectedResult) {
|
||||
return array(
|
||||
'antagonist' => $candidateTest,
|
||||
'expectedResults' => $expectedResults,
|
||||
'actualResults' => $actualResults,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
namespace Civi\CiUtil\Command;
|
||||
|
||||
/**
|
||||
* Class CompareCommand
|
||||
*
|
||||
* @package Civi\CiUtil\Command
|
||||
*/
|
||||
class CompareCommand {
|
||||
/**
|
||||
* @param $argv
|
||||
*/
|
||||
public static function main($argv) {
|
||||
if (empty($argv[1])) {
|
||||
echo "summary: Compares the output of different test runs\n";
|
||||
echo "usage: phpunit-compare [--out=txt|csv] [--phpunit-json|--jenkins-xml] <file1> <file2>...\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults');
|
||||
$printerType = 'txt';
|
||||
$suites = array(); // array('file' => string, 'results' => array)
|
||||
for ($i = 1; $i < count($argv); $i++) {
|
||||
switch ($argv[$i]) {
|
||||
case '--phpunit-json':
|
||||
$parser = array('\Civi\CiUtil\PHPUnitParser', 'parseJsonResults');
|
||||
break;
|
||||
|
||||
case '--jenkins-xml':
|
||||
$parser = array('\Civi\CiUtil\JenkinsParser', 'parseXmlResults');
|
||||
break;
|
||||
|
||||
case '--csv':
|
||||
$parser = array('\Civi\CiUtil\CSVParser', 'parseResults');
|
||||
break;
|
||||
|
||||
case '--out=txt':
|
||||
$printerType = 'txt';
|
||||
break;
|
||||
|
||||
case '--out=csv':
|
||||
$printerType = 'csv';
|
||||
break;
|
||||
|
||||
default:
|
||||
$suites[] = array(
|
||||
'file' => $argv[$i],
|
||||
'results' => call_user_func($parser, file_get_contents($argv[$i])),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$tests = array(); // array(string $name)
|
||||
foreach ($suites as $suite) {
|
||||
$tests = array_unique(array_merge(
|
||||
$tests,
|
||||
array_keys($suite['results'])
|
||||
));
|
||||
}
|
||||
sort($tests);
|
||||
|
||||
if ($printerType == 'csv') {
|
||||
$printer = new \Civi\CiUtil\CsvPrinter('php://stdout', \Civi\CiUtil\Arrays::collect($suites, 'file'));
|
||||
}
|
||||
else {
|
||||
$printer = new \Civi\CiUtil\ComparisonPrinter(\Civi\CiUtil\Arrays::collect($suites, 'file'));
|
||||
}
|
||||
foreach ($tests as $test) {
|
||||
$values = array();
|
||||
foreach ($suites as $suite) {
|
||||
$values[] = isset($suite['results'][$test]) ? $suite['results'][$test] : 'MISSING';
|
||||
}
|
||||
|
||||
if (count(array_unique($values)) > 1) {
|
||||
$printer->printRow($test, $values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
21
sites/all/modules/civicrm/Civi/CiUtil/Command/LsCommand.php
Normal file
21
sites/all/modules/civicrm/Civi/CiUtil/Command/LsCommand.php
Normal file
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
namespace Civi\CiUtil\Command;
|
||||
|
||||
/**
|
||||
* Class LsCommand
|
||||
*
|
||||
* @package Civi\CiUtil\Command
|
||||
*/
|
||||
class LsCommand {
|
||||
/**
|
||||
* @param $argv
|
||||
*/
|
||||
public static function main($argv) {
|
||||
$paths = $argv;
|
||||
array_shift($paths);
|
||||
foreach (\Civi\CiUtil\PHPUnitScanner::findTestsByPath($paths) as $test) {
|
||||
printf("%s %s %s\n", $test['file'], $test['class'], $test['method']);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue