From 9d7c9bfb8a2c14b4b0b8ee84d8eec253abc53fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhold=20F=C3=BCreder?= Date: Thu, 21 Apr 2022 13:16:39 +0200 Subject: [PATCH] Fix HTML report merging for multiple suites So far only the suites of the first HTML report were in the final merged HTML report. And when the first HTML report (luckily) already contained all suites, then all tests from the other HTML reports were always merged into the first suite (instead of the same non-first one). --- src/Merger/HtmlReportMerger.php | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Merger/HtmlReportMerger.php b/src/Merger/HtmlReportMerger.php index 88f198d..8701085 100644 --- a/src/Merger/HtmlReportMerger.php +++ b/src/Merger/HtmlReportMerger.php @@ -150,21 +150,29 @@ public function run(): void throw XPathExpressionException::malformedXPath($xpathExprSuiteNodes); } - $j = 0; - foreach ($suiteNodes as $suiteNode) { + // Do not process the "summary" node anymore: + for ($j = 0; $j < $suiteNodes->length - 1; $j++) { + $suiteNode = $suiteNodes->item($j); + if ($suiteNode->getAttribute('class') == '') { - //move to next reference node - ++$j; - if ($j > $refnodes->length - 1) { - break; + // Find matching reference node + $toFind = $suiteNode->nodeValue; + $idxOfRefNode = $this->findRefNodeIdx($refnodes, $toFind); + // if not found it is a new suite => append suite header and insert at the end == insert before the last one (= summary) + if ($idxOfRefNode == -1) { + $suiteNode = $dstHTML->importNode($suiteNode, true); + $table->insertBefore($suiteNode, $refnodes->item($refnodes->length)); + + $insertIdx = $refnodes->length + 1; + } else { + $insertIdx = $idxOfRefNode + 1; } - continue; } //insert nodes before current reference node $suiteNode = $dstHTML->importNode($suiteNode, true); - $table->insertBefore($suiteNode, $refnodes->item($j)); + $table->insertBefore($suiteNode, $refnodes->item($insertIdx)); } } @@ -185,6 +193,15 @@ public function run(): void libxml_use_internal_errors($this->previousLibXmlUseErrors); } + private function findRefNodeIdx(DOMNodeList $refNodes, string $nodeValue) { + for ($i = 0; $i < $refNodes->count(); $i++) { + if ($refNodes->item($i)->nodeValue == $nodeValue) { + return $i; + } + } + return -1; + } + /** * This function sums all execution time of each report * @param DOMDocument $dstFile