mageekguy\atoum\scripts\runner::enableAutorun PHP Method

enableAutorun() public static method

public static enableAutorun ( $name )
    public static function enableAutorun($name)
    {
        static $autorunIsRegistered = false;
        if (static::$autorunner instanceof static) {
            throw new exceptions\runtime('Unable to autorun \'' . $name . '\' because \'' . static::$autorunner->getName() . '\' is already set as autorunner');
        }
        if ($autorunIsRegistered === false) {
            $autorunner =& static::$autorunner;
            $calledClass = get_called_class();
            register_shutdown_function(function () use(&$autorunner, $calledClass) {
                if ($autorunner instanceof $calledClass) {
                    set_error_handler(function ($error, $message, $file, $line) use($autorunner) {
                        if (error_reporting() !== 0) {
                            $autorunner->writeError($message . ' in ' . $file . ' at line ' . $line, $error);
                            exit(3);
                        }
                    });
                    try {
                        $score = $autorunner->run()->getRunner()->getScore();
                        $isSuccess = $score->getFailNumber() <= 0 && $score->getErrorNumber() <= 0 && $score->getExceptionNumber() <= 0;
                        if ($autorunner->shouldFailIfVoidMethods() && $score->getVoidMethodNumber() > 0) {
                            $isSuccess = false;
                        }
                        if ($autorunner->shouldFailIfSkippedMethods() && $score->getSkippedMethodNumber() > 0) {
                            $isSuccess = false;
                        }
                        exit($isSuccess ? 0 : 1);
                    } catch (\exception $exception) {
                        $autorunner->writeError($exception->getMessage());
                        exit(2);
                    }
                }
            });
            $autorunIsRegistered = true;
        }
        static::$autorunner = new static($name);
        foreach (static::$configurationCallables as $callable) {
            try {
                static::$autorunner->useConfigurationCallable($callable);
            } catch (\exception $exception) {
                static::$autorunner->writeError($exception->getMessage());
                static::$autorunner = null;
                exit($exception->getCode());
            }
        }
        return static::$autorunner;
    }

Usage Example

Beispiel #1
0
<?php

namespace mageekguy\atoum;

use mageekguy\atoum\scripts;
require_once __DIR__ . '/../classes/autoloader.php';
if (defined(__NAMESPACE__ . '\\scripts\\runner') === false) {
    define(__NAMESPACE__ . '\\scripts\\runner', __FILE__);
}
if (scripts\runner::autorunMustBeEnabled() === true) {
    scripts\runner::enableAutorun(constant(__NAMESPACE__ . '\\scripts\\runner'));
}