silverstripe-framework/tests/FullTestSuite.php
Ingo Schommer 98e8dd035c ENHANCEMENT Added "module=" argument to FullTestSuite (to support comma-separated module lists)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/branches/2.4@111489 467b73ca-7a2a-4603-9d3b-597d59a354a9
2011-02-02 14:19:53 +13:00

80 lines
2.1 KiB
PHP

<?php
@require_once('sapphire/tests/bootstrap.php');
/**
* Alternative to letting PHPUnit handle class retrieval via
* traversing the filesystem. Works around restrictions of PHPUnit
* on running tests on multiple directories at once, without resorting
* to group or testsuite definitions in a custom phpunit.xml file.
*
* Usage:
* - "phpunit sapphire/tests/FullTestSuite.php"
* (all tests)
* - "phpunit sapphire/tests/FullTestSuite.php '' module=sapphire,cms"
* (comma-separated modules. empty quotes are necessary to avoid PHPUnit argument confusion)
*
* See http://www.phpunit.de/manual/current/en/organizing-tests.html#organizing-tests.testsuite
*
* Note: We can't unit test this class because of segfaults in PHP5.3 when trying to
* use get_all_tests() within a SapphireTest.
*
* @package sapphire
* @subpackage testing
*/
class FullTestSuite {
/**
* Called by the PHPUnit runner to gather runnable tests.
*
* @return PHPUnit_Framework_TestSuite
*/
public static function suite() {
$suite = new PHPUnit_Framework_TestSuite();
if(isset($_GET['module'])) {
$classList = self::get_module_tests($_GET['module']);
} else {
$classList = self::get_all_tests();
}
foreach($classList as $className) {
$suite->addTest(new SapphireTestSuite($className));
}
return $suite;
}
/**
* @return Array
*/
public static function get_all_tests() {
ManifestBuilder::load_test_manifest();
$tests = ClassInfo::subclassesFor('SapphireTest');
array_shift($tests);
return $tests;
}
/**
* Run tests for one or more "modules".
* A module is generally a toplevel folder, e.g. "mysite" or "sapphire".
*
* @param String $nameStr
* @return Array
*/
protected static function get_module_tests($namesStr) {
$tests = array();
$names = explode(',', $namesStr);
foreach($names as $name) {
$classesForModule = ClassInfo::classes_for_folder($name);
if($classesForModule) foreach($classesForModule as $class) {
if(class_exists($class) && is_subclass_of($class, 'SapphireTest')) {
$tests[] = $class;
}
}
}
return $tests;
}
}