Chris@14
|
1 <?php
|
Chris@14
|
2 /*
|
Chris@14
|
3 * This file is part of the php-code-coverage package.
|
Chris@14
|
4 *
|
Chris@14
|
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
|
Chris@14
|
6 *
|
Chris@14
|
7 * For the full copyright and license information, please view the LICENSE
|
Chris@14
|
8 * file that was distributed with this source code.
|
Chris@14
|
9 */
|
Chris@14
|
10
|
Chris@14
|
11 namespace SebastianBergmann\CodeCoverage\Report\Xml;
|
Chris@14
|
12
|
Chris@14
|
13 class Unit
|
Chris@14
|
14 {
|
Chris@14
|
15 /**
|
Chris@14
|
16 * @var \DOMElement
|
Chris@14
|
17 */
|
Chris@14
|
18 private $contextNode;
|
Chris@14
|
19
|
Chris@14
|
20 public function __construct(\DOMElement $context, $name)
|
Chris@14
|
21 {
|
Chris@14
|
22 $this->contextNode = $context;
|
Chris@14
|
23
|
Chris@14
|
24 $this->setName($name);
|
Chris@14
|
25 }
|
Chris@14
|
26
|
Chris@14
|
27 private function setName($name)
|
Chris@14
|
28 {
|
Chris@14
|
29 $this->contextNode->setAttribute('name', $name);
|
Chris@14
|
30 }
|
Chris@14
|
31
|
Chris@14
|
32 public function setLines($start, $executable, $executed)
|
Chris@14
|
33 {
|
Chris@14
|
34 $this->contextNode->setAttribute('start', $start);
|
Chris@14
|
35 $this->contextNode->setAttribute('executable', $executable);
|
Chris@14
|
36 $this->contextNode->setAttribute('executed', $executed);
|
Chris@14
|
37 }
|
Chris@14
|
38
|
Chris@14
|
39 public function setCrap($crap)
|
Chris@14
|
40 {
|
Chris@14
|
41 $this->contextNode->setAttribute('crap', $crap);
|
Chris@14
|
42 }
|
Chris@14
|
43
|
Chris@14
|
44 public function setPackage($full, $package, $sub, $category)
|
Chris@14
|
45 {
|
Chris@14
|
46 $node = $this->contextNode->getElementsByTagNameNS(
|
Chris@14
|
47 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
48 'package'
|
Chris@14
|
49 )->item(0);
|
Chris@14
|
50
|
Chris@14
|
51 if (!$node) {
|
Chris@14
|
52 $node = $this->contextNode->appendChild(
|
Chris@14
|
53 $this->contextNode->ownerDocument->createElementNS(
|
Chris@14
|
54 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
55 'package'
|
Chris@14
|
56 )
|
Chris@14
|
57 );
|
Chris@14
|
58 }
|
Chris@14
|
59
|
Chris@14
|
60 $node->setAttribute('full', $full);
|
Chris@14
|
61 $node->setAttribute('name', $package);
|
Chris@14
|
62 $node->setAttribute('sub', $sub);
|
Chris@14
|
63 $node->setAttribute('category', $category);
|
Chris@14
|
64 }
|
Chris@14
|
65
|
Chris@14
|
66 public function setNamespace($namespace)
|
Chris@14
|
67 {
|
Chris@14
|
68 $node = $this->contextNode->getElementsByTagNameNS(
|
Chris@14
|
69 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
70 'namespace'
|
Chris@14
|
71 )->item(0);
|
Chris@14
|
72
|
Chris@14
|
73 if (!$node) {
|
Chris@14
|
74 $node = $this->contextNode->appendChild(
|
Chris@14
|
75 $this->contextNode->ownerDocument->createElementNS(
|
Chris@14
|
76 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
77 'namespace'
|
Chris@14
|
78 )
|
Chris@14
|
79 );
|
Chris@14
|
80 }
|
Chris@14
|
81
|
Chris@14
|
82 $node->setAttribute('name', $namespace);
|
Chris@14
|
83 }
|
Chris@14
|
84
|
Chris@14
|
85 public function addMethod($name)
|
Chris@14
|
86 {
|
Chris@14
|
87 $node = $this->contextNode->appendChild(
|
Chris@14
|
88 $this->contextNode->ownerDocument->createElementNS(
|
Chris@14
|
89 'http://schema.phpunit.de/coverage/1.0',
|
Chris@14
|
90 'method'
|
Chris@14
|
91 )
|
Chris@14
|
92 );
|
Chris@14
|
93
|
Chris@14
|
94 return new Method($node, $name);
|
Chris@14
|
95 }
|
Chris@14
|
96 }
|