ENHANCEMENT: added SapphireTest:: boolean to flag tests that should be skipped from the TestRunner

This commit is contained in:
Will Rossiter 2011-09-26 16:08:41 +13:00
parent 60ea09bb42
commit e740bf8a65
3 changed files with 32 additions and 5 deletions

View File

@ -57,6 +57,9 @@ class FunctionalTest extends SapphireTest {
}
function setUp() {
// Skip calling FunctionalTest directly.
if(get_class($this) == "FunctionalTest") self::$skip_test = true;
parent::setUp();
$this->mainSession = new TestSession();
@ -70,7 +73,7 @@ class FunctionalTest extends SapphireTest {
// Unprotect the site, tests are running with the assumption it's off. They will enable it on a case-by-case basis.
BasicAuth::protect_entire_site(false);
SecurityToken::disable();
}

View File

@ -19,6 +19,13 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
*/
static $fixture_file = null;
/**
* Set whether to include this test in the TestRunner or to skip this.
*
* @var bool
*/
private static $skip_test = false;
/**
* @var Boolean If set to TRUE, this will force a test database to be generated
* in {@link setUp()}. Note that this flag is overruled by the presence of a
@ -93,6 +100,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
* Helper arrays for illegalExtensions/requiredExtensions code
*/
private $extensionsToReapply = array(), $extensionsToRemove = array();
/**
* Determines if unit tests are currently run (via {@link TestRunner}).
@ -113,6 +121,18 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
protected $fixtures;
function setUp() {
// We cannot run the tests on this abstract class.
if(get_class($this) == "SapphireTest") self::$skip_test = true;
// Ensure we are to run this test case
if(self::$skip_test) {
$this->markTestSkipped(sprintf(
'Skipping %s ', get_class($this)
));
return;
}
// Mark test as being run
$this->originalIsRunningTest = self::$is_running_test;
self::$is_running_test = true;

View File

@ -234,15 +234,19 @@ class TestRunner extends Controller {
self::use_test_manifest();
$classNames = array();
$moduleNames = explode(',', $request->param('ModuleName'));
foreach($moduleNames as $moduleName) {
$classesForModule = ClassInfo::classes_for_folder($moduleName);
if($classesForModule) foreach($classesForModule as $class) {
if(class_exists($class) && is_subclass_of($class, 'SapphireTest')) {
$classNames[] = $class;
if($classesForModule) {
foreach($classesForModule as $className) {
if(class_exists($className) && is_subclass_of($className, 'SapphireTest')) {
$classNames[] = $className;
}
}
}
}
$this->runTests($classNames, $coverage);
}