/** * Returns HTML code list contains tree of files spesified by class properties. * * @return string HTML code */ public function getNavigation() { //--- Create real path: $this->path = realpath($this->path); //--- Create filePatterns from given stripExtention: if ($this->stripExtention && !$this->filePatterns) { $this->filePatterns = '.*' . preg_quote($this->stripExtention) . '$'; } //--- Select all files by patterns: $files = Files::globFiles($this->path, $this->filePatterns, $this->excludePatterns, $this->recursive); //--- Get requested file: $activeFile = $_REQUEST[$this->routerPrefix]; //--- Add file extention: if ($activeFile && $this->stripExtention) { $activeFile .= $this->stripExtention; } //--- Check: Is it my file?: if (!isset($files[rtrim($this->path, '/') . '/' . $activeFile])) { $activeFile = ''; } //--- Get default file (first): if (!$activeFile) { $name = array_keys($files)[0]; $base = array_values($files)[0]; $activeFile = preg_replace('/^' . preg_quote($base . '/', '/') . '/', '', $name); } //--- Set current item: $this->currentItem = $activeFile; //--- Create HTML code of tree: return Html::arrayToList(Files::getFilesTree($files), $this->listType, null, function (&$tag, &$body, &$attr) { if ($tag == 'li' && preg_match('/(.*)\\.\\w+$/', $body, $m)) { if ($body == $this->currentItem) { $attr['class'] = $this->cssActive; } if ($this->stripExtention) { $body = preg_replace('/' . preg_quote($this->stripExtention) . '$/', '', $body); } $body = Html::getElement('a', basename($m[1]), ['href' => '?' . $this->routerPrefix . '=' . $body]); } }); }
/** * To find all existing PHPUnit results xml-files. * * @param string $targetPath (Option) new path to PHPUnit results xml-files. * @return hash Array of testSuites structure: * @code * Array ( [someFile.xml] => Array ( [@attributes] => Array ( [name] => someTest [file] => someFile.xml [tests] => [assertions] => [failures] => 1 [errors] => [time] => [base] => basePath ) [testcase] => Array ( [0] => Array ( [@attributes] => Array ( [name] => [class] => [file] => [line] => [assertions] => [time] => ) [failure] => some failure ) ) [someFile2.xml] => Array( ... ) ... * @endcode */ public function findAll($targetPath = NULL) { //--- Find all xml files of results: $targetPath = $this->getTargetPath($targetPath); $files = Files::globFiles($targetPath, "\\.xml\$", NULL, true); $this->testsStructure = Files::getFilesTree($files); $testSuites = array(); //--- Load results to common array: if (is_array($files)) { foreach ($files as $fileName => $basePath) { $data = Data::load($fileName, false); if (!empty($data["testsuite"]["@attributes"])) { $data["testsuite"]["@attributes"]["base"] = $basePath; $testSuites[$fileName] = $data["testsuite"]; } } } //echo "<listing>"; print_r($testSuites); exit; $this->testSuites = $testSuites; return $this->testSuites; }
/** * Generate all tastes by input config or by class default values * * @param hash $config Config params (class properties values) * @throws Exception * @return hash An array of generated files. (Array structure see in @ref getResult) * @see getResult */ public function generate($config = NULL) { //--- Set configuration: Data::set($this, $config); // $this->setConfig($config); //--- Get input files: $inputFiles = Files::globFiles($this->sourcePaths, $this->sourcePatterns, $this->sourceExclude, $this->sourceRecursive); //$this->getSources(); if (empty($inputFiles)) { throw new Exception("no input files"); } //--- Create and set destination root path: if ($this->destinationRoot && !is_dir($this->destinationRoot)) { mkdir($this->destinationRoot, 0777, true); } $destinationRoot = realpath($this->destinationRoot); if (!$destinationRoot) { throw new Exception("[destinationRoot] does not exists"); } //--- Create files: foreach ($inputFiles as $inputFile => $base) { //--- Create files with sub directories: if ($this->destinationTree) { $path = substr(dirname($inputFile), strlen($base)) . "/"; $path = $destinationRoot . $path; //if (!is_dir($path)) { // mkdir ($path, 0777, true); //} //--- Create files in same directory: } else { $path = $destinationRoot . "/"; } //--- Create output file name: $outputFile = $path . Basic::replace($this->testFileName, array("NAME" => preg_replace('/\\.[^\\.]*$/', "", basename($inputFile)))); //--- Generate file: try { $this->generateFile($inputFile, $outputFile); $destinations[$outputFile] = "test"; } catch (Exception $e) { $errors[$outputFile] = $e->getMessage(); } } //--- Create common run file: if ($this->runFileName) { $runFile = $destinationRoot . "/" . basename($this->runFileName); $runBody = $this->generateRunFile($destinations, $destinationRoot); if ($runBody) { if (file_put_contents($runFile, $runBody) === FALSE) { $errors[$runFile] = "Can't create run file"; } else { chmod($runFile, 0755); //--- set execute rights $destinations[$runFile] = "run"; } } } //--- Create result data: $this->resultData['destinations'] = $destinations; $this->resultData['errors'] = $errors; //--- return $this->getResult(); }