FUnit::run PHP Method

run() public static method

Run the registered tests, and output a report
See also: FUnit::run_tests()
See also: FUnit::report()
public static run ( boolean $report = true, string $filter = null, $report_format = null )
$report boolean whether or not to output a report after tests run. Default true.
$filter string optional test case name filter
    public static function run($report = true, $filter = null, $report_format = null)
    {
        // create a new current suite if needed
        static::check_current_suite();
        // get the suite
        $suite = static::get_current_suite();
        if (static::$disable_run) {
            FUnit::debug_out("Not running tests because of \$disable_run");
            return;
        }
        // set handlers
        $old_error_handler = set_error_handler('\\FUnit::error_handler');
        // run the tests in the suite
        FUnit::debug_out("Running tests in suite '" . $suite->getName() . "'");
        $run_tests = $suite->run($filter);
        if (static::$disable_reporting) {
            FUnit::debug_out("Reporting disabled");
            $report = false;
        }
        if ($report) {
            FUnit::debug_out("Printing report for tests run in suite '" . $suite->getName() . "'");
            static::report($report_format, $run_tests);
        } else {
            FUnit::debug_out("Not printing report for tests run in suite '" . $suite->getName() . "'");
        }
        // add this suite's data to the static $all_run_tests
        static::$all_run_tests = array_merge(static::$all_run_tests, $run_tests);
        // restore handlers
        if ($old_error_handler) {
            set_error_handler($old_error_handler);
        }
        $exit_code = $suite->getExitCode();
        static::$current_suite_name = null;
        return $exit_code;
    }

Usage Example

<?php

/**
 * you should run this standalone (not with the test runner)
 */
use FUnit as fu;
use FUnit\TestSuite;
require_once __DIR__ . '/../../src/FUnit.php';
fu::test('FUnit::set_disable_reporting(true)', function () {
    fu::set_disable_reporting(true);
    fu::equal(true, fu::$disable_reporting, "\$disable_reporting is true");
});
fu::set_silence(true);
fu::set_disable_reporting(false);
fu::run();
All Usage Examples Of FUnit::run