|
18 | 18 | */ |
19 | 19 | final class Coverage |
20 | 20 | { |
21 | | - private readonly XMLWriter $writer; |
22 | 21 | private readonly DOMElement $contextNode; |
23 | | - private bool $finalized = false; |
| 22 | + private readonly string $line; |
24 | 23 |
|
25 | 24 | public function __construct(DOMElement $context, string $line) |
26 | 25 | { |
27 | 26 | $this->contextNode = $context; |
28 | | - |
29 | | - $this->writer = new XMLWriter; |
30 | | - $this->writer->openMemory(); |
31 | | - $this->writer->startElementNs(null, $context->nodeName, 'https://schema.phpunit.de/coverage/1.0'); |
32 | | - $this->writer->writeAttribute('nr', $line); |
| 27 | + $this->line = $line; |
33 | 28 | } |
34 | 29 |
|
35 | | - /** |
36 | | - * @throws ReportAlreadyFinalizedException |
37 | | - */ |
38 | | - public function addTest(string $test): void |
| 30 | + public function finalize(array $tests): void |
39 | 31 | { |
40 | | - if ($this->finalized) { |
41 | | - // @codeCoverageIgnoreStart |
42 | | - throw new ReportAlreadyFinalizedException; |
43 | | - // @codeCoverageIgnoreEnd |
| 32 | + $xml = '<line nr="'. $this->line .'">'; |
| 33 | + foreach ($tests as $test) { |
| 34 | + $xml .= '<covered by="'. htmlspecialchars($test, ENT_QUOTES | ENT_XML1) .'" />'; |
44 | 35 | } |
45 | | - |
46 | | - $this->writer->startElement('covered'); |
47 | | - $this->writer->writeAttribute('by', $test); |
48 | | - $this->writer->endElement(); |
49 | | - } |
50 | | - |
51 | | - public function finalize(): void |
52 | | - { |
53 | | - $this->writer->endElement(); |
| 36 | + $xml .= '</line>'; |
54 | 37 |
|
55 | 38 | $fragment = $this->contextNode->ownerDocument->createDocumentFragment(); |
56 | | - $fragment->appendXML($this->writer->outputMemory()); |
| 39 | + $fragment->appendXML($xml); |
57 | 40 |
|
58 | 41 | $this->contextNode->parentNode->replaceChild( |
59 | 42 | $fragment, |
|
0 commit comments