File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change 1010namespace SebastianBergmann \CodeCoverage \Report \Xml ;
1111
1212use DOMElement ;
13- use SebastianBergmann \CodeCoverage \ReportAlreadyFinalizedException ;
1413use XMLWriter ;
1514
1615/**
1918final class Coverage
2019{
2120 private readonly DOMElement $ contextNode ;
21+ private bool $ finalized = false ;
2222 private readonly string $ line ;
2323
2424 public function __construct (DOMElement $ context , string $ line )
@@ -29,14 +29,20 @@ public function __construct(DOMElement $context, string $line)
2929
3030 public function finalize (array $ tests ): void
3131 {
32- $ xml = '<line nr=" ' . $ this ->line .'"> ' ;
32+ $ writer = new XMLWriter ;
33+ $ writer ->openMemory ();
34+ $ writer ->startElementNs (null , $ this ->contextNode ->nodeName , 'https://schema.phpunit.de/coverage/1.0 ' );
35+ $ writer ->writeAttribute ('nr ' , $ this ->line );
36+
3337 foreach ($ tests as $ test ) {
34- $ xml .= '<covered by=" ' . htmlspecialchars ($ test , ENT_QUOTES | ENT_XML1 ) .'" /> ' ;
38+ $ writer ->startElement ('covered ' );
39+ $ writer ->writeAttribute ('by ' , $ test );
40+ $ writer ->endElement ();
3541 }
36- $ xml .= ' </line> ' ;
42+ $ writer -> endElement () ;
3743
3844 $ fragment = $ this ->contextNode ->ownerDocument ->createDocumentFragment ();
39- $ fragment ->appendXML ($ xml );
45+ $ fragment ->appendXML ($ writer -> outputMemory () );
4046
4147 $ this ->contextNode ->parentNode ->replaceChild (
4248 $ fragment ,
You can’t perform that action at this time.
0 commit comments