2010-10-19 05:36:48 +02:00
|
|
|
<?php
|
2010-10-19 05:41:34 +02:00
|
|
|
@require_once('sapphire/tests/bootstrap.php');
|
2010-10-19 05:36:48 +02:00
|
|
|
|
2010-10-19 05:55:44 +02:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2010-10-19 05:36:48 +02:00
|
|
|
class FullTestSuite {
|
2010-10-19 05:55:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2010-10-19 05:47:39 +02:00
|
|
|
|
2010-10-19 05:55:44 +02:00
|
|
|
/**
|
|
|
|
* @return Array
|
|
|
|
*/
|
|
|
|
public static function get_all_tests() {
|
2010-10-19 05:36:48 +02:00
|
|
|
ManifestBuilder::load_test_manifest();
|
|
|
|
$tests = ClassInfo::subclassesFor('SapphireTest');
|
|
|
|
array_shift($tests);
|
2010-10-19 05:47:39 +02:00
|
|
|
|
2010-10-19 05:36:48 +02:00
|
|
|
return $tests;
|
|
|
|
}
|
2010-10-19 05:55:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
|
|
|
}
|
2010-10-19 05:36:48 +02:00
|
|
|
}
|
|
|
|
|
2010-10-19 05:55:44 +02:00
|
|
|
return $tests;
|
2010-10-19 05:47:39 +02:00
|
|
|
}
|
2010-10-19 05:36:48 +02:00
|
|
|
}
|
|
|
|
|