mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Added "module=" argument to FullTestSuite (to support comma-separated module lists) (from r111489)
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@112906 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
dd1c02cd90
commit
976f96ee0a
@ -1,35 +1,79 @@
|
||||
<?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 {
|
||||
|
||||
public static function get_tests() {
|
||||
ManifestBuilder::load_test_manifest();
|
||||
$tests = ClassInfo::subclassesFor('SapphireTest');
|
||||
array_shift($tests);
|
||||
unset($tests['FunctionalTest']);
|
||||
|
||||
// Remove tests that don't need to be executed every time
|
||||
unset($tests['PhpSyntaxTest']);
|
||||
|
||||
foreach($tests as $class => $v) {
|
||||
$reflection = new ReflectionClass($class);
|
||||
if (!$reflection->isInstantiable()) {
|
||||
unset($tests[$class]);
|
||||
}
|
||||
}
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by the PHPUnit runner to gather runnable tests.
|
||||
*
|
||||
* @return PHPUnit_Framework_TestSuite
|
||||
*/
|
||||
public static function suite() {
|
||||
$suite = new PHPUnit_Framework_TestSuite();
|
||||
$classList = self::get_tests();
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user