public function render()
 {
     $editor = new OpenInEditor();
     $structure = (object) array('structure' => array());
     $isAll = true;
     foreach (Finder::findFiles('*Test.php')->from($this->dir) as $file) {
         $relative = substr($file, strlen($this->dir) + 1);
         $cursor =& $structure;
         foreach (explode(DIRECTORY_SEPARATOR, $relative) as $d) {
             $r = isset($cursor->relative) ? $cursor->relative . DIRECTORY_SEPARATOR : NULL;
             $cursor =& $cursor->structure[$d];
             $path = $this->dir . DIRECTORY_SEPARATOR . $r . $d;
             $open = $path === $this->open;
             if ($open) {
                 $isAll = false;
             }
             $cursor = (object) array('relative' => $r . $d, 'name' => $d, 'open' => $open, 'structure' => isset($cursor->structure) ? $cursor->structure : array(), 'editor' => $editor->link($path, 1), 'mode' => is_file($path) ? 'file' : 'folder');
             if (!$cursor->structure and $cursor->mode === 'file') {
                 foreach ($this->loadMethod($path) as $l => $m) {
                     $cursor->structure[$m] = (object) array('relative' => $cursor->relative . '::' . $m, 'name' => $m, 'open' => $cursor->open and $this->method === $m, 'structure' => array(), 'editor' => $editor->link($path, $l), 'mode' => 'method');
                 }
             }
         }
         $cursor->name = $file->getBasename();
     }
     $this->template->isAll = ($isAll and $this->open !== false);
     $this->template->basePath = TemplateFactory::getBasePath();
     $this->template->structure = $structure->structure;
     $this->template->setFile(__DIR__ . '/StructureRenderer.latte');
     $this->template->render();
 }
示例#2
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();
 }