1 | <?php |
||
6 | class Reader extends MetaProvider |
||
7 | { |
||
8 | /** |
||
9 | * @var \SimpleXMLElement |
||
10 | */ |
||
11 | protected $xml; |
||
12 | |||
13 | /** |
||
14 | * @var bool |
||
15 | */ |
||
16 | protected $isSingle = false; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $suites = array(); |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $logFile; |
||
27 | |||
28 | /** |
||
29 | * @var array |
||
30 | */ |
||
31 | protected static $defaultSuite = array('name' => '', |
||
32 | 'file' => '', |
||
33 | 'tests' => 0, |
||
34 | 'assertions' => 0, |
||
35 | 'failures' => 0, |
||
36 | 'errors' => 0, |
||
37 | 'time' => 0); |
||
38 | |||
39 | 54 | public function __construct($logFile) |
|
40 | { |
||
41 | 54 | if (!file_exists($logFile)) { |
|
42 | 1 | throw new \InvalidArgumentException("Log file $logFile does not exist"); |
|
43 | } |
||
44 | |||
45 | 54 | $this->logFile = $logFile; |
|
46 | 54 | if (filesize($logFile) == 0) { |
|
47 | throw new \InvalidArgumentException("Log file $logFile is empty. This means a PHPUnit process has crashed."); |
||
48 | } |
||
49 | 54 | $logFileContents = file_get_contents($this->logFile); |
|
50 | 54 | $this->xml = new \SimpleXMLElement($logFileContents); |
|
51 | 54 | $this->init(); |
|
52 | 54 | } |
|
53 | |||
54 | /** |
||
55 | * Returns whether or not this reader contains only |
||
56 | * a single suite |
||
57 | * |
||
58 | * @return bool |
||
59 | */ |
||
60 | 2 | public function isSingleSuite() |
|
64 | |||
65 | /** |
||
66 | * Return the Reader's collection |
||
67 | * of test suites |
||
68 | * |
||
69 | * @return array |
||
70 | */ |
||
71 | 15 | public function getSuites() |
|
75 | |||
76 | /** |
||
77 | * Return an array that contains |
||
78 | * each suite's instant feedback. Since |
||
79 | * logs do not contain skipped or incomplete |
||
80 | * tests this array will contain any number of the following |
||
81 | * characters: .,F,E |
||
82 | * |
||
83 | * @return array |
||
84 | */ |
||
85 | 12 | public function getFeedback() |
|
102 | |||
103 | /** |
||
104 | * Remove the JUnit xml file |
||
105 | */ |
||
106 | 3 | public function removeLog() |
|
110 | |||
111 | /** |
||
112 | * Initialize the suite collection |
||
113 | * from the JUnit xml document |
||
114 | */ |
||
115 | 54 | protected function init() |
|
123 | |||
124 | /** |
||
125 | * Uses an array of testcase nodes to build a suite |
||
126 | * @param array $nodeArray an array of SimpleXMLElement nodes representing testcase elements |
||
127 | */ |
||
128 | 54 | protected function initSuiteFromCases($nodeArray) |
|
138 | |||
139 | /** |
||
140 | * Creates and adds a TestSuite based on the given |
||
141 | * suite properties and collection of test cases |
||
142 | * |
||
143 | * @param $properties |
||
144 | * @param $testCases |
||
145 | */ |
||
146 | 44 | protected function addSuite($properties, $testCases) |
|
152 | |||
153 | /** |
||
154 | * Fold an array of testcase nodes into a suite array |
||
155 | * @param array $nodeArray an array of testcase nodes |
||
156 | * @param array $testCases an array reference. Individual testcases will be placed here. |
||
157 | * @return mixed |
||
158 | */ |
||
159 | 54 | protected function caseNodesToSuiteProperties($nodeArray, &$testCases = array()) |
|
160 | { |
||
161 | 54 | $cb = array('ParaTest\\Logging\\JUnit\\TestCase', 'caseFromNode'); |
|
162 | return array_reduce($nodeArray, function ($result, $c) use (&$testCases, $cb) { |
||
163 | 54 | $testCases[] = call_user_func_array($cb, array($c)); |
|
164 | 54 | $result['name'] = (string)$c['class']; |
|
165 | 54 | $result['file'] = (string)$c['file']; |
|
166 | 54 | $result['tests'] = $result['tests'] + 1; |
|
167 | 54 | $result['assertions'] += (int)$c['assertions']; |
|
168 | 54 | $result['failures'] += sizeof($c->xpath('failure')); |
|
169 | 54 | $result['errors'] += sizeof($c->xpath('error')); |
|
170 | 54 | $result['time'] += floatval($c['time']); |
|
171 | 54 | return $result; |
|
172 | 54 | }, static::$defaultSuite); |
|
173 | } |
||
174 | |||
175 | /** |
||
176 | * Return a collection of testcase nodes |
||
177 | * from the xml document |
||
178 | * |
||
179 | * @return array |
||
180 | */ |
||
181 | 54 | protected function getCaseNodes() |
|
194 | |||
195 | /** |
||
196 | * Determine if this reader is a single suite |
||
197 | * and initialize the suite collection with the first |
||
198 | * suite |
||
199 | */ |
||
200 | 54 | protected function initSuite() |
|
212 | } |
||
213 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.