Version 1
[yaffs-website] / vendor / phpunit / php-code-coverage / src / CodeCoverage / Report / XML / Project.php
1 <?php
2 /*
3  * This file is part of the PHP_CodeCoverage package.
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
11 /**
12  * @since Class available since Release 2.0.0
13  */
14 class PHP_CodeCoverage_Report_XML_Project extends PHP_CodeCoverage_Report_XML_Node
15 {
16     public function __construct($name)
17     {
18         $this->init();
19         $this->setProjectName($name);
20     }
21
22     private function init()
23     {
24         $dom = new DOMDocument;
25         $dom->loadXML('<?xml version="1.0" ?><phpunit xmlns="http://schema.phpunit.de/coverage/1.0"><project/></phpunit>');
26
27         $this->setContextNode(
28             $dom->getElementsByTagNameNS(
29                 'http://schema.phpunit.de/coverage/1.0',
30                 'project'
31             )->item(0)
32         );
33     }
34
35     private function setProjectName($name)
36     {
37         $this->getContextNode()->setAttribute('name', $name);
38     }
39
40     public function getTests()
41     {
42         $testsNode = $this->getContextNode()->getElementsByTagNameNS(
43             'http://schema.phpunit.de/coverage/1.0',
44             'tests'
45         )->item(0);
46
47         if (!$testsNode) {
48             $testsNode = $this->getContextNode()->appendChild(
49                 $this->getDom()->createElementNS(
50                     'http://schema.phpunit.de/coverage/1.0',
51                     'tests'
52                 )
53             );
54         }
55
56         return new PHP_CodeCoverage_Report_XML_Tests($testsNode);
57     }
58
59     public function asDom()
60     {
61         return $this->getDom();
62     }
63 }