Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions PHP/CodeCoverage/Report/XML.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private function processFile(PHP_CodeCoverage_Report_Node_File $file, PHP_CodeCo
foreach ($tests as $test) {
$coverage->addTest($test);
}
$coverage->finalize();
}

$this->initTargetDirectory(
Expand Down
43 changes: 34 additions & 9 deletions PHP/CodeCoverage/Report/XML/File/Coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,56 @@
*/
class PHP_CodeCoverage_Report_XML_File_Coverage
{

/**
* @var XMLWriter
*/
private $writer;

/**
* @var DOMElement
*/
private $contextNode;

/**
* @var bool
*/
private $finalized = false;


public function __construct(DOMElement $context, $line)
{
$this->contextNode = $context;

$this->setLine($line);
$this->writer = new XMLWriter();
$this->writer->openMemory();
$this->writer->startElementNs(null, $context->nodeName, 'http://schema.phpunit.de/coverage/1.0');
$this->writer->writeAttribute('nr', $line);
}

private function setLine($line)
public function addTest($test)
{
$this->contextNode->setAttribute('nr', $line);
if ($this->finalized) {
throw new PHP_CodeCoverage_Exception('Coverage Report already finalized');
}

$this->writer->startElement('covered');
$this->writer->writeAttribute('by', $test);
$this->writer->endElement();
}

public function addTest($test)
public function finalize()
{
$covered = $this->contextNode->appendChild(
$this->contextNode->ownerDocument->createElementNS(
'http://schema.phpunit.de/coverage/1.0', 'covered'
)
$this->writer->endElement();

$fragment = $this->contextNode->ownerDocument->createDocumentFragment();
$fragment->appendXML($this->writer->outputMemory());

$this->contextNode->parentNode->replaceChild(
$fragment,
$this->contextNode
);

$covered->setAttribute('by', $test);
$this->finalized = true;
}
}