コード例 #1
0
/**
 * Load the tests that are defined in the named modules.
 *
 * If you have Tests/Foo.php which defines a test class called
 * Tests_Foo, the call would look like:
 *
 * loadTests('Tests/', array('Foo'))
 *
 * @param string $test_dir The root of the test hierarchy. Must end
 * with a /
 *
 * @param array $test_names The names of the modules in which the
 * tests are defined. This should not include the root of the test
 * hierarchy.
 */
function loadTests($test_dir, $test_names)
{
    global $_tests;
    $suites = array();
    foreach ($test_names as $filename) {
        $filename = $test_dir . $filename . '.php';
        $class_name = str_replace('/', '_', $filename);
        $class_name = basename($class_name, '.php');
        if (!global_require_once($filename)) {
            continue;
        }
        $test = new $class_name($class_name);
        if (is_a($test, 'PHPUnit_TestCase')) {
            $s = new PHPUnit_TestSuite();
            $s->setName($class_name);
            $s->addTestSuite($class_name);
            $test = $s;
            $tc_array_name = $class_name . '_other';
            if (array_key_exists($tc_array_name, $GLOBALS) && is_array($GLOBALS[$tc_array_name])) {
                foreach ($GLOBALS[$tc_array_name] as $tc) {
                    $test->addTestSuite(get_class($tc));
                }
            }
        }
        $suites[] = $test;
    }
    return $suites;
}
コード例 #2
0
function makeSuite($class_name)
{
    $test = new $class_name($class_name);
    if (is_a($test, 'PHPUnit_TestCase')) {
        $s = new PHPUnit_TestSuite();
        $s->setName($class_name);
        $s->addTestSuite($class_name);
        $test = $s;
    }
    $tc_array_name = $class_name . '_other';
    if (array_key_exists($tc_array_name, $GLOBALS) && is_array($GLOBALS[$tc_array_name])) {
        foreach ($GLOBALS[$tc_array_name] as $tc) {
            $test->addTestSuite(get_class($tc));
        }
    }
    return $test;
}