/**
  * Turns test results to plugin criteria or error.
  * Goal names will be used as criterion names. Criteria will be passed with
  * 100% fulfillment if goal was reached or failed with goal error as failure
  * info otherwise.
  *	@throws PluginException in case test finished with error(s), so that the
  *		error is returned as plugin error
  */
 private function createCriteriaFromTest()
 {
     if (count($this->results['errors'])) {
         throw new PluginException("Failure. " . StringUtils::indent(implode("\n", $this->results['errors'])));
     }
     foreach ($this->test->getGoals() as $goalId => $goalName) {
         $this->addCriterion($goalName);
         $results = $this->results['results'][$goalId];
         $passed = $results['reached'];
         $fulfillment = $passed ? 100 : 0;
         $details = !$passed && $results['error'] ? StringUtils::indent(trim($results['error'])) . "\n" : '';
         $this->updateCriterion($goalName, $passed, $fulfillment, $details);
     }
 }
 /**
  * Turns managed tests' results to plugin criteria or errors.
  * For criterion to be passed, all goals specified for that criterion when
  * @ref addTesterCriterion() "adding it" must be reached. Otherwise the
  * criterion is failed with fulfillment percentage based on number of failed
  * goals and failure info created by joining failure information of failed goals.
  */
 private function checkTesterCriteria()
 {
     $failedTests = array();
     foreach ($this->testerCriteria as $criterionName => $criterionConfig) {
         $goalCount = 0;
         $goalsFailed = 0;
         $details = '';
         foreach ($criterionConfig as $testId => $goalIds) {
             if ($goalIds === null) {
                 $goalIds = $criterionConfig[$testId] = array_keys($this->tests[$testId]->getGoals());
             }
             $goalCount += count($goalIds);
             $results = $this->testResults[$testId];
             foreach ($goalIds as $goalId) {
                 $goal = isset($results['results'][$goalId]) ? $results['results'][$goalId] : array();
                 if (count($results['errors'])) {
                     ++$goalsFailed;
                     if (!$failedTests[$testId]) {
                         $failedTests[$testId] = true;
                         $details .= $results['name'] . ' didn\'t successfully finish' . "\n" . StringUtils::indent(implode("\n", $results['errors']));
                     }
                 } elseif (!$goal['reached']) {
                     ++$goalsFailed;
                     $errorStr = $goal['error'] ? StringUtils::indent(trim($goal['error'])) . "\n" : '';
                     $details .= "{$goal['name']} ({$results['name']}) failed\n" . $errorStr;
                 }
             }
         }
         $fulfillment = $goalCount > 0 ? floor(($goalCount - $goalsFailed) * 100 / $goalCount) : 100;
         $this->updateCriterion($criterionName, $goalsFailed == 0, $fulfillment, $details);
     }
 }