private function prepareTextReport(Collector $collector)
 {
     $textReport = new TextReport();
     $out = $textReport->prepareMutantsReport($collector->getEscaped(), 'Escapes');
     if ($collector->getTimeoutCount() > 0) {
         $out .= PHP_EOL . $textReport->prepareMutantsReport($collector->getTimeouts(), 'Timeouts');
     }
     if ($collector->getErrorCount() > 0) {
         $out .= PHP_EOL . $textReport->prepareMutantsReport($collector->getErrors(), 'Errors');
     }
     return $out;
 }
Exemple #2
0
 private function runCache(IncrementalCache $cache, CoverageData $coverage, Collector $collector, $mutableFile, $index)
 {
     static $fileHits = [];
     static $cacheHits = [];
     if (in_array($mutableFile, $cacheHits)) {
         return true;
     } elseif (in_array($mutableFile, $fileHits)) {
         return false;
     }
     $fileHits[] = $mutableFile;
     $testFilesHaveChanged = $cache->hasModifiedTestFiles($coverage, $mutableFile);
     $sourceFilesHaveChanged = $cache->hasModifiedSourceFiles($mutableFile);
     if ($cache->hasResultsFor($mutableFile) && $testFilesHaveChanged === false && $sourceFilesHaveChanged === false) {
         $resultSet = $cache->getResultsFor($mutableFile);
         foreach ($resultSet as $result) {
             if ($result['isShadow'] === false) {
                 $resultObject = unserialize($result['result']);
                 $collector->collect($resultObject);
                 $this->onMutantDone($resultObject, $index);
             } else {
                 $mutantObject = unserialize($result['result']);
                 $collector->collectShadow($mutantObject);
                 $this->onShadowMutant($index);
             }
         }
         $cacheHits[] = $mutableFile;
         return true;
     }
     return false;
 }
 protected function logJson(Collector $collector)
 {
     $vanquishedTotal = $collector->getVanquishedTotal();
     $measurableTotal = $collector->getMeasurableTotal();
     if ($measurableTotal !== 0) {
         $detectionRateTested = round(100 * ($vanquishedTotal / $measurableTotal));
     } else {
         $detectionRateTested = 0;
     }
     if ($collector->getTotalCount() !== 0) {
         $uncoveredRate = round(100 * ($collector->getShadowCount() / $collector->getTotalCount()));
         $detectionRateAll = round(100 * ($collector->getVanquishedTotal() / $collector->getTotalCount()));
     } else {
         $uncoveredRate = 0;
         $detectionRateAll = 0;
     }
     $out = ['summary' => ['total' => $collector->getTotalCount(), 'kills' => $collector->getKilledCount(), 'escapes' => $collector->getEscapeCount(), 'errors' => $collector->getErrorCount(), 'timeouts' => $collector->getTimeoutCount(), 'notests' => $collector->getShadowCount(), 'covered_score' => $detectionRateTested, 'combined_score' => $detectionRateAll, 'mutation_coverage' => 100 - $uncoveredRate], 'escaped' => []];
     $out = array_merge($out, $collector->toGroupedMutantArray());
     file_put_contents($this->jsonLogFile, json_encode($out, JSON_PRETTY_PRINT));
 }
Exemple #4
0
 /**
  * Render message that mutation testing loop is starting
  *
  * @param Collector $collector
  */
 public function renderSummaryReport(Collector $collector)
 {
     $pkills = str_pad($collector->getKilledCount(), 8, ' ', STR_PAD_LEFT);
     $pescapes = str_pad($collector->getEscapeCount(), 8, ' ', STR_PAD_LEFT);
     $perrors = str_pad($collector->getErrorCount(), 8, ' ', STR_PAD_LEFT);
     $ptimeouts = str_pad($collector->getTimeoutCount(), 8, ' ', STR_PAD_LEFT);
     $pshadows = str_pad($collector->getShadowCount(), 8, ' ', STR_PAD_LEFT);
     $this->write(PHP_EOL, false);
     $this->write($collector->getTotalCount() . ' mutations were generated:');
     $this->write($pkills . ' mutants were killed');
     $this->write($pshadows . ' mutants were not covered by tests');
     $this->write($pescapes . ' covered mutants were not detected');
     $this->write($perrors . ' fatal errors were encountered');
     $this->write($ptimeouts . ' time outs were encountered');
     $this->write(PHP_EOL, false);
     $vanquishedTotal = $collector->getVanquishedTotal();
     $measurableTotal = $collector->getMeasurableTotal();
     if ($measurableTotal !== 0) {
         $detectionRateTested = round(100 * ($vanquishedTotal / $measurableTotal));
     } else {
         $detectionRateTested = 0;
     }
     if ($collector->getTotalCount() !== 0) {
         $coveredRate = round(100 * ($measurableTotal / $collector->getTotalCount()));
         $detectionRateAll = round(100 * ($vanquishedTotal / $collector->getTotalCount()));
     } else {
         $coveredRate = 0;
         $detectionRateAll = 0;
     }
     $this->write('Metrics:');
     $this->write('    Mutation Score Indicator (MSI): <options=bold>' . $detectionRateAll . '%</options=bold>');
     $this->write('    Mutation Code Coverage: <options=bold>' . $coveredRate . '%</options=bold>');
     $this->write('    Covered Code MSI: <options=bold>' . $detectionRateTested . '%</options=bold>');
     $this->write(PHP_EOL, false);
     $this->write('Remember that some mutants will inevitably be harmless (i.e. false positives).');
 }