1
0
mirror of synced 2024-12-13 14:56:01 +03:00

implemented -group and -filter checks to the command line testrunner

This commit is contained in:
meus 2007-09-02 21:51:04 +00:00
parent 42e76aa7a3
commit 1b23da2bd7
2 changed files with 48 additions and 12 deletions

View File

@ -19,11 +19,27 @@ class GroupTest extends UnitTestCase
}
}
public function run(HtmlReporter $reporter)
public function shouldBeRun($testCase, $filter){
if( ! is_array($filter)){
return true;
}
foreach($filter as $subFilter){
$name = strtolower(get_class($testCase));
$pos = strpos($name, strtolower($subFilter));
//it can be 0 so we have to use === to see if false
if($pos === false){
return false;
}
}
return true;
}
public function run(HtmlReporter $reporter, $filter)
{
$reporter->paintHeader();
foreach ($this->_testCases as $k => $testCase) {
if ( ! $this->shouldBeRun($testCase, $filter)) {
continue;
}
$testCase->run();
$this->_passed += $testCase->getPassCount();
$this->_failed += $testCase->getFailCount();

View File

@ -2,6 +2,25 @@
ini_set('max_execution_time', 900);
function parseOptions($array) {
$currentName="";
$options=array();
foreach($array as $name){
if(strpos($name,"-")===0) {
$name=str_replace("-","",$name);
$currentName=$name;
if( ! isset($options[$currentName])) {
$options[$currentName]=array();
}
} else {
$values=$options[$currentName];
array_push($values,$name);
$options[$currentName]=$values;
}
}
return $options;
}
function autoload($class) {
if(strpos($class, 'TestCase') === false) {
return false;
@ -424,15 +443,11 @@ if (PHP_SAPI === "cli") {
$argv = $_SERVER["argv"];
array_shift($argv);
$coverage = false;
if(isset($argv[0]) && $argv[0] == "coverage"){
array_shift($argv);
$coverage = true;
}
$options = parseOptions($argv);
if( ! empty($argv)) {
if( isset($options["group"])) {
$testGroup = new GroupTest("Custom");
foreach($argv as $group) {
foreach($options["group"] as $group) {
if( ! isset($$group)) {
if (class_exists($group)) {
$testGroup->addTestCase(new $group);
@ -444,13 +459,18 @@ if( ! empty($argv)) {
} else {
$testGroup = $test;
}
if ($coverage) {
$filter = "";
if(isset($options["filter"])){
$filter = $options["filter"];
}
if (isset($options["coverage"])) {
xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
$testGroup->run($reporter);
$testGroup->run($reporter, $filter);
$result["path"] = Doctrine::getPath() . DIRECTORY_SEPARATOR;
$result["coverage"] = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
file_put_contents("coverage.txt", serialize($result));
} else {
$testGroup->run($reporter);
$testGroup->run($reporter, $filter);
}