1
0
mirror of synced 2024-12-13 22:56:04 +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(); $reporter->paintHeader();
foreach ($this->_testCases as $k => $testCase) { foreach ($this->_testCases as $k => $testCase) {
if ( ! $this->shouldBeRun($testCase, $filter)) {
continue;
}
$testCase->run(); $testCase->run();
$this->_passed += $testCase->getPassCount(); $this->_passed += $testCase->getPassCount();
$this->_failed += $testCase->getFailCount(); $this->_failed += $testCase->getFailCount();

View File

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