Ejemplo n.º 1
0
 /**
  * Returns array of assets obtained from assets-files.
  * 
  * The method loads and combines multiple arrays into one.
  * 
  * @param  array $assetFiles List of files returns array of data.
  * @param string $assetPath (option) Path to find files with data.
  * @return <i>array</i> Merged arrays data.
  */
 public static function getAssets($assetFiles, $assetPath = null)
 {
     if (!is_array($assetFiles)) {
         $assetFiles = [$assetFiles];
     }
     $allAssets = null;
     foreach ($assetFiles as $assetFile) {
         //--- Include asset files: (silent)
         if ($assetFile) {
             if ($assetPath) {
                 $assetPath .= DIRECTORY_SEPARATOR;
             }
             $assetFile = $assetPath . $assetFile;
             if (!file_exists($assetFile)) {
                 continue;
             }
             $assets = (require $assetFile);
             if (!is_array($assets)) {
                 continue;
             }
             if (!is_array($allAssets)) {
                 $allAssets = [];
             }
             Data::setArray($allAssets, $assets);
         }
     }
     //--- Change base link to relative link for assets files (css, javascript)
     if (is_array($allAssets)) {
         $checkList = ['css', 'js'];
         foreach ($checkList as $target) {
             if (is_array($allAssets[$target])) {
                 foreach ($allAssets[$target] as $index => $link) {
                     $allAssets[$target][$index] = self::getRelativeLink($allAssets[$target][$index]);
                 }
             }
         }
     }
     return $allAssets;
 }
Ejemplo n.º 2
0
 /**
 * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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();
 }