Example #1
0
/**
 *    Exit handler to run all recent test cases and exit system if in CLI
 */
function simpletest_autorun()
{
    if (tests_have_run()) {
        return;
    }
    $result = run_local_tests();
    if (SimpleReporter::inCli()) {
        exit($result ? 0 : 1);
    }
}
Example #2
0
/**
 *    Exit handler to run all recent test cases if no test has
 *    so far been run. Uses the DefaultReporter which can have
 *    it's output controlled with SimpleTest::prefer().
 */
function simpletest_autorun()
{
    if (tests_have_run()) {
        return;
    }
    $candidates = array_intersect(capture_new_classes(), classes_defined_in_initial_file());
    $loader = new SimpleFileLoader();
    $suite = $loader->createSuiteFromClasses(basename(initial_file()), $loader->selectRunnableTests($candidates));
    $result = $suite->run(new DefaultReporter());
    if (SimpleReporter::inCli()) {
        exit($result ? 0 : 1);
    }
}
Example #3
0
/**
 *    run all recent test cases if no test has
 *    so far been run. Uses the DefaultReporter which can have
 *    it's output controlled with SimpleTest::prefer().
 *    @return boolean/null false if there were test failures, true if
 *                         there were no failures, null if tests are
 *                         already running
 */
function run_local_tests()
{
    try {
        if (tests_have_run()) {
            return;
        }
        $candidates = capture_new_classes();
        $loader = new SimpleFileLoader();
        $suite = $loader->createSuiteFromClasses(basename(initial_file()), $loader->selectRunnableTests($candidates));
        return $suite->run(new DefaultReporter());
    } catch (Exception $stack_frame_fix) {
        print $stack_frame_fix->getMessage();
        return false;
    }
}
Example #4
0
/**
 *    Exit handler to run all recent test cases if no test has
 *    so far been run. Uses the DefaultReporter which can have
 *    it's output controlled with SimpleTest::prefer().
 */
function simpletest_autorun()
{
    try {
        if (tests_have_run()) {
            return;
        }
        $candidates = array_intersect(capture_new_classes(), classes_defined_in_initial_file());
        $loader = new SimpleFileLoader();
        $suite = $loader->createSuiteFromClasses(basename(initial_file()), $loader->selectRunnableTests($candidates));
        $result = $suite->run(new DefaultReporter());
    } catch (Exception $e) {
        // This is here, because under normal circumstances shutdown
        // functions don't have a stack frame, leading to obscure errors.
        echo $e->__toString();
        $result = false;
    }
    if (SimpleReporter::inCli()) {
        exit($result ? 0 : 1);
    }
}