diff --git a/test/lib/coverage.php b/test/lib/coverage.php index 252d3648db..4e612f5228 100644 --- a/test/lib/coverage.php +++ b/test/lib/coverage.php @@ -62,12 +62,15 @@ class coverage /** * Load saved traces from file. * + * @param string $key * @access public - * @return array + * @return array|string */ - private function loadTraceFromFile(): array + private function loadTraceFromFile(string $key = ''): array|string { - return json_decode(file_get_contents($this->traceFile), true); + $report = json_decode(file_get_contents($this->traceFile), true); + if($key == '') return $report; + return isset($report[$key]) ? $report[$key] : array(); } /** @@ -75,7 +78,6 @@ class coverage * * @access public * @return string - */ public function getTraceFile(): string { return $this->traceFile; @@ -90,7 +92,7 @@ class coverage */ private function mergeTraces(array $traces): array { - $savedTraces = $this->loadTraceFromFile(); + $savedTraces = $this->loadTraceFromFile('traces'); if(!is_array($savedTraces)) return $traces; @@ -132,7 +134,12 @@ class coverage $traces = $this->groupTraceByModule($traces); $traces = $this->mergeTraces($traces); - return file_put_contents($this->traceFile, json_encode($traces)); + $log = new stdclass; + $log->time = date('Y-m-d H:i:s'); + $log->ztfPath = getenv('ZTF_REPORT_DIR'); + $log->traces = $traces; + + return file_put_contents($this->traceFile, json_encode($log)); } /** @@ -332,72 +339,10 @@ EOT; public function genSummaryReport(string $module='', string $file=''): string { /* Get trace from file. */ - $traces = $this->loadTraceFromFile(); + $traces = $this->loadTraceFromFile('traces'); /* Generate report. */ - $reportHtml = ''; - $reportHtml .= '