Tester\CodeCoverage\Collector::start PHP Method

start() public static method

Starts gathering the information for code coverage.
public static start ( $file ) : void
return void
    public static function start($file)
    {
        if (self::isStarted()) {
            throw new \LogicException('Code coverage collector has been already started.');
        }
        self::$file = fopen($file, 'c+');
        if (defined('PHPDBG_VERSION') && PHP_VERSION_ID >= 70000) {
            phpdbg_start_oplog();
            self::$collector = 'collectPhpDbg';
        } elseif (extension_loaded('xdebug')) {
            xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
            self::$collector = 'collectXdebug';
        } else {
            $alternative = PHP_VERSION_ID >= 70000 ? ' or phpdbg SAPI' : '';
            throw new \LogicException("Code coverage functionality requires Xdebug extension{$alternative}.");
        }
        register_shutdown_function(function () {
            register_shutdown_function([__CLASS__, 'save']);
        });
    }

Usage Example

Esempio n. 1
0
 public static function setup($rootDir)
 {
     // configure environment
     umask(0);
     Tester\Environment::setup();
     class_alias('Tester\\Assert', 'Assert');
     date_default_timezone_set('Europe/Prague');
     // create temporary directory
     define('TEMP_DIR', $rootDir . '/tmp/' . (isset($_SERVER['argv']) ? md5(serialize($_SERVER['argv'])) : getmypid()));
     Tester\Helpers::purge(TEMP_DIR);
     @chmod(TEMP_DIR, 0777);
     Nette\Diagnostics\Debugger::$logDirectory = TEMP_DIR;
     $_SERVER = array_intersect_key($_SERVER, array_flip(array('PHP_SELF', 'SCRIPT_NAME', 'SERVER_ADDR', 'SERVER_SOFTWARE', 'HTTP_HOST', 'DOCUMENT_ROOT', 'OS', 'argc', 'argv')));
     $_SERVER['REQUEST_TIME'] = 1234567890;
     $_ENV = $_GET = $_POST = $_FILES = array();
     if (extension_loaded('xdebug')) {
         xdebug_disable();
         Tester\CodeCoverage\Collector::start($rootDir . '/coverage.dat');
     }
 }
All Usage Examples Of Tester\CodeCoverage\Collector::start