2010-10-19 05:36:48 +02:00
|
|
|
<?php
|
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:
|
2012-03-24 04:38:57 +01:00
|
|
|
* - "phpunit framework/tests/FullTestSuite.php"
|
2010-10-19 05:55:44 +02:00
|
|
|
* (all tests)
|
2012-03-24 04:38:57 +01:00
|
|
|
* - "phpunit framework/tests/FullTestSuite.php '' module=framework,cms"
|
2010-10-19 05:55:44 +02:00
|
|
|
* (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.
|
|
|
|
*
|
2012-04-12 08:02:46 +02:00
|
|
|
* @package framework
|
2010-10-19 05:55:44 +02:00
|
|
|
* @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() {
|
2012-03-24 04:38:57 +01:00
|
|
|
require_once(dirname(__FILE__) . '/bootstrap.php');
|
2011-09-26 05:08:31 +02:00
|
|
|
|
2010-10-19 05:55:44 +02:00
|
|
|
$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() {
|
2012-03-24 04:38:57 +01:00
|
|
|
require_once(dirname(__FILE__) . '/bootstrap.php');
|
2011-09-26 05:08:31 +02:00
|
|
|
|
2011-03-18 07:38:02 +01:00
|
|
|
TestRunner::use_test_manifest();
|
2010-10-19 05:36:48 +02:00
|
|
|
$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".
|
2012-03-24 04:38:57 +01:00
|
|
|
* A module is generally a toplevel folder, e.g. "mysite" or "framework".
|
2010-10-19 05:55:44 +02:00
|
|
|
*
|
|
|
|
* @param String $nameStr
|
|
|
|
* @return Array
|
|
|
|
*/
|
|
|
|
protected static function get_module_tests($namesStr) {
|
2012-03-24 04:38:57 +01:00
|
|
|
require_once(dirname(__FILE__) . '/bootstrap.php');
|
2011-09-26 05:08:31 +02:00
|
|
|
|
2010-10-19 05:55:44 +02:00
|
|
|
$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
|
|
|
}
|
|
|
|
|