Exemple #1
0
 /**
  * RUN FOREST!!!
  * @param string dir to tests
  * @param string params {@see self::arg()}
  * @throws DirectoryNotFoundException
  */
 public function run($dir, $arg = '--no-globals-backup --strict')
 {
     $template = TemplateFactory::create(__DIR__ . '/layout.latte');
     $template->testDir = $this->testDir;
     $template->method = $this->method;
     $this->arg($arg);
     $arg = $this->prepareArgs($dir);
     $onBefore = $this->onBefore;
     $_this = $this;
     $template->onBefore = function () use($onBefore, $_this, $dir) {
         foreach ($onBefore as $cb) {
             $cb($_this, $dir);
         }
     };
     if ($this->run) {
         $command = new Command();
         $printer = new ResultPrinter();
         $printer->debug = (bool) $this->debug;
         $printer->dir = $dir . DIRECTORY_SEPARATOR;
         $template->run = function () use($command, $printer, $arg) {
             while (@ob_end_flush()) {
             }
             flush();
             $command->run($arg, $printer);
             $printer->render();
         };
     } else {
         $template->run = false;
         $uri = rtrim($_SERVER['REQUEST_URI'], '?&');
         $uri .= strpos($uri, '?') === false ? '?' : '&';
         $uri .= 'run';
         $template->startUri = $uri;
     }
     $onAfter = $this->onAfter;
     $template->onAfter = function () use($onAfter) {
         foreach ($onAfter as $cb) {
             $cb();
         }
     };
     $template->render();
 }