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();

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
@ -94,6 +101,7 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
*/
private $extensionsToReapply = array(), $extensionsToRemove = array();
/**
* Determines if unit tests are currently run (via {@link TestRunner}).
* This is used as a cheap replacement for fully mockable state
@ -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,11 +234,15 @@ 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;
}
}
}
}