Beispiel #1
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $logger = $ziper->logger;
     $project = $ziper->project;
     $logger->log('Executing PHP Unit');
     $parts = array('phpunit', '--log-tap ' . ECRPATH_LOGS . '/phpunit.log', $this->arguments, $this->filedir);
     $cmd = implode(' ', $parts);
     $cmd = escapeshellcmd($cmd);
     $logger->log($cmd);
     $output = shell_exec($cmd . ' 2>&1 | tee -a ' . $ziper->logFile);
     if (false == JFile::exists(ECRPATH_LOGS . '/phpunit.log')) {
         $logger->log('PHP Unit Tests failed to run', 'Action', JLog::ERROR);
         return $this;
     }
     $log = JFile::read(ECRPATH_LOGS . '/phpunit.log');
     //$pattern = "/not ok (\d+) - ([a-Z]+):/";
     $pattern = "/not ok (\\d+) - (\\w+):/";
     preg_match_all($pattern, $log, $matches);
     $failures = array();
     $errors = array();
     if ($matches && isset($matches[2])) {
         //foreach($matches[2])
         $type = $matches[2][0];
         switch ($type) {
             case 'Failure':
                 $failures[] = $matches[0][0];
                 break;
             case 'Error':
                 $errors[] = $matches[0][0];
                 break;
             default:
                 $ziper->logger->log(__METHOD__ . ' - unknown type: ' . $type);
         }
         $logger->log('PHP Unit results:');
         //$logger->log(sprintf('Files processed: %s', $filesProcessed));
         $logger->log(sprintf('Failures: %d', count($failures)));
         $logger->log(sprintf('Errors:   %d', count($errors)));
         if (0 != $this->failureThreshold) {
             if (count($failures) >= $this->failureThreshold) {
                 $ziper->addFailure(sprintf('%s: The failure threshold of %d has been exceeded (%d failures)', $this->name, $this->failureThreshold, count($failures)));
                 $ziper->setInvalid();
             }
         }
         if (0 != $this->errorThreshold) {
             if (count($errors) >= $this->errorThreshold) {
                 $ziper->addFailure(sprintf('%s: The error threshold of %d has been exceeded (%d errors)', $this->name, $this->errorThreshold, count($errors)));
                 $ziper->setInvalid();
             }
         }
     }
     return $this;
 }
Beispiel #2
0
 /**
  * Perform the action.
  *
  * @param EcrProjectZiper $ziper
  *
  * @return EcrProjectAction
  */
 public function run(EcrProjectZiper $ziper)
 {
     $logger = $ziper->logger;
     $project = $ziper->project;
     $logger->log('Executing CodeSniffer');
     $files = implode(' ', $project->copies);
     $ignore = $this->ignore ? '--ignore=' . $this->ignore : '';
     $extensions = $this->extensions ? '--extensions=' . $this->extensions : '';
     $parts = array('phpcs', '-p', '--report=summary', '--standard=' . $this->standard, $ignore, $this->arguments, $files);
     $cmd = implode(' ', $parts);
     $cmd = escapeshellcmd($cmd);
     $logger->log($cmd);
     $output = shell_exec($cmd . ' 2>&1 | tee -a ' . $ziper->logFile);
     $pattern = "/A TOTAL OF (\\d+) ERROR\\(S\\) AND (\\d+) WARNING\\(S\\) WERE FOUND IN (\\d+) FILE\\(S\\)/";
     preg_match_all($pattern, $output, $matches);
     if ($matches && isset($matches[3])) {
         $errors = isset($matches[1][0]) ? $matches[1][0] : 'n/a';
         $warnings = isset($matches[2][0]) ? $matches[2][0] : 'n/a';
         $filesProcessed = isset($matches[3][0]) ? $matches[3][0] : 'n/a';
         $logger->log('PHP CodeSniffer results:');
         $logger->log(sprintf('Files processed: %s', $filesProcessed));
         $logger->log(sprintf('Errors:   %s', $errors));
         $logger->log(sprintf('Warnings: %s', $warnings));
         if (0 != $this->warningThreshold) {
             if ($warnings >= $this->warningThreshold) {
                 $ziper->addFailure(sprintf('%s: The warning threshold of %d has been exceeded (%d warnings)', $this->name, $this->warningThreshold, $warnings));
                 $ziper->setInvalid();
             }
         }
         if (0 != $this->errorThreshold) {
             if ($errors >= $this->errorThreshold) {
                 $ziper->addFailure(sprintf('%s: The error threshold of %d has been exceeded (%d errors)', $this->name, $this->errorThreshold, $errors));
                 $ziper->setInvalid();
             }
         }
     }
     return $this;
 }