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 | 52 | public function __construct($logFile) |
|
40 | { |
||
41 | 52 | if (!file_exists($logFile)) { |
|
42 | 1 | throw new \InvalidArgumentException("Log file $logFile does not exist"); |
|
43 | } |
||
44 | |||
45 | 52 | $this->logFile = $logFile; |
|
46 | 52 | if (filesize($logFile) == 0) { |
|
47 | throw new \InvalidArgumentException("Log file $logFile is empty. This means a PHPUnit process has crashed."); |
||
48 | } |
||
49 | 52 | $logFileContents = file_get_contents($this->logFile); |
|
50 | 52 | $this->xml = new \SimpleXMLElement($logFileContents); |
|
51 | 52 | $this->init(); |
|
52 | 52 | } |
|
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 | 12 | public function getSuites() |
|
75 | |||
76 | /** |
||
77 | * Checks whether the xml log has |
||
78 | * test suite results |
||
79 | * |
||
80 | * @return array |
||
81 | */ |
||
82 | 12 | public function hasResults() |
|
86 | |||
87 | /** |
||
88 | * Return an array that contains |
||
89 | * each suite's instant feedback. Since |
||
90 | * logs do not contain skipped or incomplete |
||
91 | * tests this array will contain any number of the following |
||
92 | * characters: .,F,E |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | 51 | public function getFeedback() |
|
97 | { |
||
98 | 12 | $feedback = array(); |
|
99 | 12 | $suites = $this->isSingle ? $this->suites : $this->suites[0]->suites; |
|
100 | 12 | foreach ($suites as $suite) { |
|
101 | 12 | foreach ($suite->cases as $case) { |
|
102 | 12 | if ($case->failures) { |
|
103 | 8 | $feedback[] = 'F'; |
|
104 | 12 | } elseif ($case->errors) { |
|
105 | 9 | $feedback[] = 'E'; |
|
106 | 9 | } else { |
|
107 | 12 | $feedback[] = '.'; |
|
108 | } |
||
109 | 12 | } |
|
110 | 12 | } |
|
111 | 51 | return $feedback; |
|
112 | 51 | } |
|
113 | |||
114 | /** |
||
115 | * Remove the JUnit xml file |
||
116 | */ |
||
117 | 51 | public function removeLog() |
|
121 | |||
122 | /** |
||
123 | * Initialize the suite collection |
||
124 | * from the JUnit xml document |
||
125 | */ |
||
126 | 52 | protected function init() |
|
134 | |||
135 | /** |
||
136 | * Uses an array of testcase nodes to build a suite |
||
137 | * @param array $nodeArray an array of SimpleXMLElement nodes representing testcase elements |
||
138 | */ |
||
139 | 51 | protected function initSuiteFromCases($nodeArray) |
|
149 | |||
150 | /** |
||
151 | * Creates and adds a TestSuite based on the given |
||
152 | * suite properties and collection of test cases |
||
153 | * |
||
154 | * @param $properties |
||
155 | * @param $testCases |
||
156 | */ |
||
157 | 41 | protected function addSuite($properties, $testCases) |
|
163 | |||
164 | /** |
||
165 | * Fold an array of testcase nodes into a suite array |
||
166 | * @param array $nodeArray an array of testcase nodes |
||
167 | * @param array $testCases an array reference. Individual testcases will be placed here. |
||
168 | * @return mixed |
||
169 | */ |
||
170 | 51 | protected function caseNodesToSuiteProperties($nodeArray, &$testCases = array()) |
|
185 | |||
186 | /** |
||
187 | * Return a collection of testcase nodes |
||
188 | * from the xml document |
||
189 | * |
||
190 | * @return array |
||
191 | */ |
||
192 | 52 | protected function getCaseNodes() |
|
205 | |||
206 | /** |
||
207 | * Determine if this reader is a single suite |
||
208 | * and initialize the suite collection with the first |
||
209 | * suite |
||
210 | */ |
||
211 | 52 | protected function initSuite() |
|
221 | } |
||
222 |
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.