ENHANCEMENT Allowing test runs per module (top-level folder), e.g. sake dev/tests/module/sapphire

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@80645 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2009-06-30 22:30:33 +00:00
parent 8ae9db13c0
commit 504980ce4d

View File

@ -25,6 +25,8 @@ require_once 'PHPUnit/TextUI/TestRunner.php';
/**
* Controller that executes PHPUnit tests.
*
* See {@link browse()} output for generic usage instructions.
*
* @package sapphire
* @subpackage testing
*/
@ -38,6 +40,7 @@ class TestRunner extends Controller {
'startsession' => 'startsession',
'endsession' => 'endsession',
'cleanupdb' => 'cleanupdb',
'module/$ModuleName' => 'module',
'$TestCase' => 'only',
);
@ -87,6 +90,7 @@ class TestRunner extends Controller {
$relativeLink = Director::makeRelative($this->Link());
echo "sake {$relativeLink}all: Run all " . count($tests) . " tests\n";
echo "sake {$relativeLink}coverage: Runs all tests and make test coverage report\n";
echo "sake {$relativeLink}module/<modulename>: Runs all tests in a module folder\n";
foreach ($tests as $test) {
echo "sake {$relativeLink}$test: Run $test\n";
}
@ -136,6 +140,23 @@ class TestRunner extends Controller {
$this->runTests($classNames);
}
}
/**
* Run tests for one or more "modules".
* A module is generally a toplevel folder, e.g. "mysite" or "sapphire".
*/
function module($request) {
$classNames = array();
$moduleNames = explode(',', $request->param('ModuleName'));
foreach($moduleNames as $moduleName) {
$classesForModule = ClassInfo::classes_for_folder($moduleName);
if($classesForModule) foreach($classesForModule as $class) {
if(is_subclass_of($class, 'SapphireTest')) $classNames[] = $class;
}
}
$this->runTests($classNames);
}
function runTests($classList, $coverage = false) {
// XDEBUG seem to cause problems with test execution :-(