Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/Merger/HtmlReportMerger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand All @@ -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
Expand Down