TestSuite   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 129
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 129
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

3 Methods

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