Skip to content

Commit

Permalink
Adding a filter GET parameter which allows you filter which test meth…
Browse files Browse the repository at this point in the history
…ods get run. It accepts preg_match() compatible patterns.
  • Loading branch information
markstory committed May 27, 2010
1 parent 8ac46c3 commit e4ccaba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
5 changes: 3 additions & 2 deletions cake/tests/lib/cake_test_suite_dispatcher.php
Expand Up @@ -37,7 +37,8 @@ class CakeTestSuiteDispatcher {
'plugin' => null,
'output' => 'html',
'show' => 'groups',
'show_passes' => false
'show_passes' => false,
'filter' => false
);

/**
Expand Down Expand Up @@ -191,7 +192,7 @@ function _groupTestList() {
function &getManager() {
if (empty($this->Manager)) {
require_once CAKE_TESTS_LIB . 'test_manager.php';
$this->Manager = new $this->_managerClass();
$this->Manager = new $this->_managerClass($this->params);
}
return $this->Manager;
}
Expand Down
25 changes: 19 additions & 6 deletions cake/tests/lib/test_manager.php
Expand Up @@ -61,6 +61,13 @@ class TestManager {
*/
public $pluginTest = false;

/**
* String to filter test case method names by.
*
* @var string
*/
public $filter = false;

/**
* TestSuite container for single or grouped test files
*
Expand All @@ -80,14 +87,20 @@ class TestManager {
*
* @return void
*/
public function __construct() {
//require_once(CAKE_TESTS_LIB . 'cake_web_test_case.php');
public function __construct($params) {
require_once(CAKE_TESTS_LIB . 'cake_test_case.php');
if (isset($_GET['app'])) {
if (isset($params['app'])) {
$this->appTest = true;
}
if (isset($_GET['plugin'])) {
$this->pluginTest = htmlentities($_GET['plugin']);
if (isset($params['plugin'])) {
$this->pluginTest = htmlentities($params['plugin']);
}
if (
isset($params['filter']) &&
$params['filter'] !== false &&
preg_match('/^[a-zA-Z0-9_]/', $params['filter'])
) {
$this->filter = '/' . $params['filter'] . '/';
}
}

Expand Down Expand Up @@ -180,7 +193,7 @@ protected function run($reporter, $codeCoverage = false) {
$reporter->paintHeader();
$testSuite = $this->getTestSuite();
$testSuite->setFixtureManager($this->getFixtureManager());
$testSuite->run($result);
$testSuite->run($result, $this->filter);
$reporter->paintResult($result);
return $result;
}
Expand Down

0 comments on commit e4ccaba

Please sign in to comment.