Hal\MutaTesting\Runner\Adapter\BaseAdapter::run PHP Method

run() public method

Run tests
public run ( string $path = null, array $options = [], string $logFile = null, string $prependFile = null, callable $callback = null ) : string
$path string
$options array
$logFile string
$prependFile string
$callback callable
return string $output
    public function run($path = null, array $options = array(), $logFile = null, $prependFile = null, callable $callback = null)
    {
        if (is_null($path)) {
            $path = $this->getTestDirectory();
        }
        $binary = escapeshellcmd($this->getBinary());
        $options = array_merge($this->getOptions(), $options);
        $args = '';
        foreach ($options as $option) {
            $args .= ' ' . $option;
        }
        $command = $this->lastCommand = "{$binary} {$args} {$path}";
        if ($this->processManager && is_callable($callback)) {
            // needed to unlink temporary file
            if (!is_null($prependFile)) {
                $cb = function () use($prependFile, $callback) {
                    unlink($prependFile);
                    $callback();
                };
            } else {
                $cb = $callback;
            }
            $process = new Process($command);
            $this->processManager->push($process, $cb);
            return null;
        } else {
            $process = new Process($command);
            $process->start();
            while ($process->isRunning()) {
            }
            if (!is_null($prependFile)) {
                unlink($prependFile);
            }
            if (!$process->isSuccessful() || strlen($process->getErrorOutput()) > 0) {
                throw new \Hal\MutaTesting\Runner\RunningException(sprintf("test terminated with an error.\nDetail: %s \n\nCommand line: %s", $process->getErrorOutput(), $process->getCommandLine()));
            }
            return $process->getOutput();
        }
    }

Usage Example

Example #1
0
 /**
  * @inherit
  */
 public function run($path = null, array $options = array(), $logFile = null, $prependFile = null, callable $callback = null)
 {
     if (!is_null($logFile)) {
         array_push($options, sprintf('--log-junit %s', $logFile));
     }
     if (!is_null($prependFile)) {
         // We cannot use php directive auto_prepend_file :
         // PHPUnit doesn't tun test in a separate process by default
         // see @link https://github.com/sebastianbergmann/phpunit/issues/930
         //
         // all the following lines should be replaced with the commented line if
         // PHPUnit change its behavior
         //
         // $options = array(sprintf('-d auto_prepend_file=%s', $bootstrapName));
         array_push($options, sprintf('--bootstrap %s', $prependFile));
         foreach ($this->getOptions() as $option) {
             $filename = false;
             if (preg_match('!-c\\s*(.*)!', $option, $matches)) {
                 $configFile = $matches[1];
                 $xml = simplexml_load_file($configFile);
                 $filename = (string) $xml['bootstrap'];
             }
             if (preg_match('!--configuration\\s*(.*)!', $option, $matches)) {
                 $configFile = $matches[1];
                 $xml = simplexml_load_file($configFile);
                 $filename = (string) $xml['bootstrap'];
             }
             if (preg_match('!--bootstrap\\s*(.*)!', $option, $matches)) {
                 $filename = $matches[1];
             }
             if ($filename) {
                 $filename = $origine = dirname($configFile) . DIRECTORY_SEPARATOR . $filename;
                 $content = file_get_contents($filename);
                 $filename = tempnam(sys_get_temp_dir(), 'tmp-botstrap');
                 $content = str_replace('__FILE__', "'{$origine}'", $content);
                 $content = str_replace('__DIR__', "'" . dirname($origine) . "'", $content);
                 file_put_contents($filename, $content);
                 file_put_contents($prependFile, sprintf("<?php require_once '%s';?>", $filename), FILE_APPEND);
             }
         }
     }
     return parent::run($path, $options, null, null, $callback);
 }
All Usage Examples Of Hal\MutaTesting\Runner\Adapter\BaseAdapter::run