Completed
Pull Request — master (#204)
by
unknown
02:07
created

TestSuite   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
c 1
b 1
f 0
lcom 0
cbo 0
dl 0
loc 108
ccs 29
cts 29
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 1
A suiteFromArray() 0 12 1
A suiteFromNode() 0 12 1
1
<?php
2
namespace ParaTest\Logging\JUnit;
3
4
/**
5
 * Class TestSuite
6
 *
7
 * A simple data structure for tracking
8
 * data associated with a testsuite node
9
 * in a JUnit xml document
10
 *
11
 * @package ParaTest\Logging\JUnit
12
 */
13
class TestSuite
14
{
15
    /**
16
     * @var string
17
     */
18
    public $name;
19
20
    /**
21
     * @var int
22
     */
23
    public $tests;
24
25
    /**
26
     * @var int
27
     */
28
    public $assertions;
29
30
    /**
31
     * @var int
32
     */
33
    public $failures;
34
35
    /**
36
     * @var int
37
     */
38
    public $errors;
39
40
    /**
41
     * @var string
42
     */
43
    public $time;
44
45
    /**
46
     * @var string
47
     */
48
    public $file;
49
50
    /**
51
     * Nested suites
52
     *
53
     * @var array
54
     */
55
    public $suites = array();
56
57
    /**
58
     * Cases belonging to this suite
59
     *
60
     * @var array
61
     */
62
    public $cases = array();
63
64 51
    public function __construct(
65
        $name,
66
        $tests,
67
        $assertions,
68
        $failures,
69
        $errors,
70
        $time,
71
        $file = null
72
    ) {
73 51
        $this->name = $name;
74 51
        $this->tests = $tests;
75 51
        $this->assertions = $assertions;
76 51
        $this->failures = $failures;
77 51
        $this->errors = $errors;
78 51
        $this->time = $time;
79 51
        $this->file = $file;
80 51
    }
81
82
    /**
83
     * Create a TestSuite from an associative
84
     * array
85
     *
86
     * @param $arr
87
     * @return TestSuite
88
     */
89 41
    public static function suiteFromArray($arr)
90
    {
91 41
        return new TestSuite(
92 41
            $arr['name'],
93 41
            $arr['tests'],
94 41
            $arr['assertions'],
95 41
            $arr['failures'],
96 41
            $arr['errors'],
97 41
            $arr['time'],
98 41
            $arr['file']
99 41
        );
100
    }
101
102
    /**
103
     * Create a TestSuite from a SimpleXMLElement
104
     *
105
     * @param \SimpleXMLElement $node
106
     * @return TestSuite
107
     */
108 51
    public static function suiteFromNode(\SimpleXMLElement $node)
109
    {
110 51
        return new TestSuite(
111 51
            (string) $node['name'],
112 51
            (string) $node['tests'],
113 51
            (string) $node['assertions'],
114 51
            (string) $node['failures'],
115 51
            (string) $node['errors'],
116 51
            (string) $node['time'],
117 51
            (string) $node['file']
118 51
        );
119
    }
120
}
121