Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of phpunit/php-code-coverage.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\CodeCoverage\Report\Xml;
11
 
12
use DOMElement;
13
use SebastianBergmann\CodeCoverage\ReportAlreadyFinalizedException;
14
use XMLWriter;
15
 
16
/**
17
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
18
 */
19
final class Coverage
20
{
21
    /**
22
     * @var XMLWriter
23
     */
24
    private $writer;
25
 
26
    /**
27
     * @var DOMElement
28
     */
29
    private $contextNode;
30
 
31
    /**
32
     * @var bool
33
     */
34
    private $finalized = false;
35
 
36
    public function __construct(DOMElement $context, string $line)
37
    {
38
        $this->contextNode = $context;
39
 
40
        $this->writer = new XMLWriter;
41
        $this->writer->openMemory();
42
        $this->writer->startElementNS(null, $context->nodeName, 'https://schema.phpunit.de/coverage/1.0');
43
        $this->writer->writeAttribute('nr', $line);
44
    }
45
 
46
    /**
47
     * @throws ReportAlreadyFinalizedException
48
     */
49
    public function addTest(string $test): void
50
    {
51
        if ($this->finalized) {
52
            throw new ReportAlreadyFinalizedException;
53
        }
54
 
55
        $this->writer->startElement('covered');
56
        $this->writer->writeAttribute('by', $test);
57
        $this->writer->endElement();
58
    }
59
 
60
    public function finalize(): void
61
    {
62
        $this->writer->endElement();
63
 
64
        $fragment = $this->contextNode->ownerDocument->createDocumentFragment();
65
        $fragment->appendXML($this->writer->outputMemory());
66
 
67
        $this->contextNode->parentNode->replaceChild(
68
            $fragment,
69
            $this->contextNode
70
        );
71
 
72
        $this->finalized = true;
73
    }
74
}