1 | <?php |
||||
2 | /** |
||||
3 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
4 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
5 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
6 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
7 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
8 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
9 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
10 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
11 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
12 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
13 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
14 | * |
||||
15 | * This software consists of voluntary contributions made by many individuals |
||||
16 | * and is licensed under the LGPL. For more information please see |
||||
17 | * <http://phing.info>. |
||||
18 | */ |
||||
19 | |||||
20 | require_once 'phing/system/io/Writer.php'; |
||||
21 | |||||
22 | /** |
||||
23 | * This abstract class describes classes that format the results of a PHPUnit testrun. |
||||
24 | * |
||||
25 | * @author Siad Ardroumli <[email protected]> |
||||
26 | * @package phing.tasks.ext.phpunit.formatter |
||||
27 | */ |
||||
28 | abstract class PHPUnitResultFormatter7 implements PHPUnit\Framework\TestListener |
||||
29 | { |
||||
30 | protected $out; |
||||
31 | |||||
32 | protected $project; |
||||
33 | |||||
34 | /** |
||||
35 | * @var bool|array |
||||
36 | */ |
||||
37 | private $timers = false; |
||||
38 | |||||
39 | /** |
||||
40 | * @var bool|array |
||||
41 | */ |
||||
42 | private $runCounts = false; |
||||
43 | |||||
44 | /** |
||||
45 | * @var bool|array |
||||
46 | */ |
||||
47 | private $failureCounts = false; |
||||
48 | |||||
49 | /** |
||||
50 | * @var bool|array |
||||
51 | */ |
||||
52 | private $errorCounts = false; |
||||
53 | |||||
54 | /** |
||||
55 | * @var bool|array |
||||
56 | */ |
||||
57 | private $incompleteCounts = false; |
||||
58 | |||||
59 | /** |
||||
60 | * @var bool|array |
||||
61 | */ |
||||
62 | private $skipCounts = false; |
||||
63 | |||||
64 | /** |
||||
65 | * @var bool|array |
||||
66 | */ |
||||
67 | private $warningCounts = false; |
||||
68 | |||||
69 | /** |
||||
70 | * Constructor |
||||
71 | * |
||||
72 | * @param PHPUnitTask $parentTask Calling Task |
||||
73 | */ |
||||
74 | 2 | public function __construct(PHPUnitTask $parentTask) |
|||
75 | { |
||||
76 | 2 | $this->project = $parentTask->getProject(); |
|||
77 | 2 | } |
|||
78 | |||||
79 | /** |
||||
80 | * Sets the writer the formatter is supposed to write its results to. |
||||
81 | * |
||||
82 | * @param Writer $out |
||||
83 | */ |
||||
84 | 2 | public function setOutput(Writer $out) |
|||
85 | { |
||||
86 | 2 | $this->out = $out; |
|||
87 | 2 | } |
|||
88 | |||||
89 | /** |
||||
90 | * Returns the extension used for this formatter |
||||
91 | * |
||||
92 | * @return string the extension |
||||
93 | */ |
||||
94 | public function getExtension() |
||||
95 | { |
||||
96 | return ''; |
||||
97 | } |
||||
98 | |||||
99 | /** |
||||
100 | * @return string |
||||
101 | */ |
||||
102 | public function getPreferredOutfile() |
||||
103 | { |
||||
104 | return ''; |
||||
105 | } |
||||
106 | |||||
107 | /** |
||||
108 | * @param PHPUnit\Framework\TestResult $result |
||||
109 | */ |
||||
110 | 2 | public function processResult(PHPUnit\Framework\TestResult $result) |
|||
111 | { |
||||
112 | 2 | } |
|||
113 | |||||
114 | 2 | public function startTestRun() |
|||
115 | { |
||||
116 | 2 | $this->timers = [$this->getMicrotime()]; |
|||
117 | 2 | $this->runCounts = [0]; |
|||
118 | 2 | $this->failureCounts = [0]; |
|||
119 | 2 | $this->errorCounts = [0]; |
|||
120 | 2 | $this->warningCounts = [0]; |
|||
121 | 2 | $this->incompleteCounts = [0]; |
|||
122 | 2 | $this->skipCounts = [0]; |
|||
123 | 2 | } |
|||
124 | |||||
125 | 2 | public function endTestRun() |
|||
126 | { |
||||
127 | 2 | } |
|||
128 | |||||
129 | /** |
||||
130 | * @param PHPUnit\Framework\TestSuite $suite |
||||
131 | */ |
||||
132 | 2 | public function startTestSuite(PHPUnit\Framework\TestSuite $suite): void |
|||
133 | { |
||||
134 | 2 | $this->timers[] = $this->getMicrotime(); |
|||
135 | 2 | $this->runCounts[] = 0; |
|||
136 | 2 | $this->failureCounts[] = 0; |
|||
137 | 2 | $this->errorCounts[] = 0; |
|||
138 | 2 | $this->incompleteCounts[] = 0; |
|||
139 | 2 | $this->skipCounts[] = 0; |
|||
140 | 2 | } |
|||
141 | |||||
142 | /** |
||||
143 | * @param PHPUnit\Framework\TestSuite $suite |
||||
144 | */ |
||||
145 | 2 | public function endTestSuite(PHPUnit\Framework\TestSuite $suite): void |
|||
146 | { |
||||
147 | 2 | $lastRunCount = array_pop($this->runCounts); |
|||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
148 | 2 | $this->runCounts[count($this->runCounts) - 1] += $lastRunCount; |
|||
149 | |||||
150 | 2 | $lastFailureCount = array_pop($this->failureCounts); |
|||
151 | 2 | $this->failureCounts[count($this->failureCounts) - 1] += $lastFailureCount; |
|||
152 | |||||
153 | 2 | $lastErrorCount = array_pop($this->errorCounts); |
|||
154 | 2 | $this->errorCounts[count($this->errorCounts) - 1] += $lastErrorCount; |
|||
155 | |||||
156 | 2 | $lastIncompleteCount = array_pop($this->incompleteCounts); |
|||
157 | 2 | $this->incompleteCounts[count($this->incompleteCounts) - 1] += $lastIncompleteCount; |
|||
158 | |||||
159 | 2 | $lastSkipCount = array_pop($this->skipCounts); |
|||
160 | 2 | $this->skipCounts[count($this->skipCounts) - 1] += $lastSkipCount; |
|||
161 | |||||
162 | 2 | array_pop($this->timers); |
|||
163 | 2 | } |
|||
164 | |||||
165 | /** |
||||
166 | * @param PHPUnit\Framework\Test $test |
||||
167 | */ |
||||
168 | 2 | public function startTest(PHPUnit\Framework\Test $test): void |
|||
169 | { |
||||
170 | 2 | $this->runCounts[count($this->runCounts) - 1]++; |
|||
0 ignored issues
–
show
It seems like
$this->runCounts can also be of type boolean ; however, parameter $var of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
171 | 2 | } |
|||
172 | |||||
173 | /** |
||||
174 | * @param PHPUnit\Framework\Test $test |
||||
175 | * @param float $time |
||||
176 | */ |
||||
177 | 2 | public function endTest(PHPUnit\Framework\Test $test, float $time): void |
|||
178 | { |
||||
179 | 2 | } |
|||
180 | |||||
181 | /** |
||||
182 | * @param PHPUnit\Framework\Test $test |
||||
183 | * @param Exception $e |
||||
184 | * @param float $time |
||||
185 | */ |
||||
186 | public function addError(PHPUnit\Framework\Test $test, Throwable $e, float $time): void |
||||
187 | { |
||||
188 | $this->errorCounts[count($this->errorCounts) - 1]++; |
||||
0 ignored issues
–
show
It seems like
$this->errorCounts can also be of type boolean ; however, parameter $var of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
189 | } |
||||
190 | |||||
191 | /** |
||||
192 | * @param PHPUnit\Framework\Test $test |
||||
193 | * @param PHPUnit\Framework\AssertionFailedError $e |
||||
194 | * @param float $time |
||||
195 | */ |
||||
196 | 1 | public function addFailure( |
|||
197 | PHPUnit\Framework\Test $test, |
||||
198 | PHPUnit\Framework\AssertionFailedError $e, |
||||
199 | float $time |
||||
200 | ): void { |
||||
201 | 1 | $this->failureCounts[count($this->failureCounts) - 1]++; |
|||
0 ignored issues
–
show
It seems like
$this->failureCounts can also be of type boolean ; however, parameter $var of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
202 | 1 | } |
|||
203 | |||||
204 | /** |
||||
205 | * @param PHPUnit\Framework\Test $test |
||||
206 | * @param PHPUnit\Framework\Warning $e |
||||
207 | * @param float $time |
||||
208 | */ |
||||
209 | public function addWarning(PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void |
||||
210 | { |
||||
211 | $this->warningCounts[count($this->warningCounts) - 1]++; |
||||
0 ignored issues
–
show
It seems like
$this->warningCounts can also be of type boolean ; however, parameter $var of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
212 | } |
||||
213 | |||||
214 | /** |
||||
215 | * @param PHPUnit\Framework\Test $test |
||||
216 | * @param Exception $e |
||||
217 | * @param float $time |
||||
218 | */ |
||||
219 | public function addIncompleteTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void |
||||
220 | { |
||||
221 | $this->incompleteCounts[count($this->incompleteCounts) - 1]++; |
||||
0 ignored issues
–
show
It seems like
$this->incompleteCounts can also be of type boolean ; however, parameter $var of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
222 | } |
||||
223 | |||||
224 | /** |
||||
225 | * @param PHPUnit\Framework\Test $test |
||||
226 | * @param Exception $e |
||||
227 | * @param float $time |
||||
228 | */ |
||||
229 | public function addSkippedTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void |
||||
230 | { |
||||
231 | $this->skipCounts[count($this->skipCounts) - 1]++; |
||||
0 ignored issues
–
show
It seems like
$this->skipCounts can also be of type boolean ; however, parameter $var of count() does only seem to accept Countable|array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
232 | } |
||||
233 | |||||
234 | /** |
||||
235 | * @param PHPUnit\Framework\Test $test |
||||
236 | * @param Exception $e |
||||
237 | * @param float $time |
||||
238 | */ |
||||
239 | public function addRiskyTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void |
||||
240 | { |
||||
241 | } |
||||
242 | |||||
243 | /** |
||||
244 | * @return mixed |
||||
245 | */ |
||||
246 | 2 | public function getRunCount() |
|||
247 | { |
||||
248 | 2 | return end($this->runCounts); |
|||
0 ignored issues
–
show
It seems like
$this->runCounts can also be of type boolean ; however, parameter $array of end() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
249 | } |
||||
250 | |||||
251 | /** |
||||
252 | * @return mixed |
||||
253 | */ |
||||
254 | 2 | public function getFailureCount() |
|||
255 | { |
||||
256 | 2 | return end($this->failureCounts); |
|||
0 ignored issues
–
show
It seems like
$this->failureCounts can also be of type boolean ; however, parameter $array of end() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
257 | } |
||||
258 | |||||
259 | /** |
||||
260 | * @return mixed |
||||
261 | */ |
||||
262 | 2 | public function getWarningCount() |
|||
263 | { |
||||
264 | 2 | return end($this->warningCounts); |
|||
0 ignored issues
–
show
It seems like
$this->warningCounts can also be of type boolean ; however, parameter $array of end() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
265 | } |
||||
266 | |||||
267 | /** |
||||
268 | * @return mixed |
||||
269 | */ |
||||
270 | 2 | public function getErrorCount() |
|||
271 | { |
||||
272 | 2 | return end($this->errorCounts); |
|||
0 ignored issues
–
show
It seems like
$this->errorCounts can also be of type boolean ; however, parameter $array of end() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
273 | } |
||||
274 | |||||
275 | /** |
||||
276 | * @return mixed |
||||
277 | */ |
||||
278 | 2 | public function getIncompleteCount() |
|||
279 | { |
||||
280 | 2 | return end($this->incompleteCounts); |
|||
0 ignored issues
–
show
It seems like
$this->incompleteCounts can also be of type boolean ; however, parameter $array of end() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
281 | } |
||||
282 | |||||
283 | /** |
||||
284 | * @return mixed |
||||
285 | */ |
||||
286 | 2 | public function getSkippedCount() |
|||
287 | { |
||||
288 | 2 | return end($this->skipCounts); |
|||
0 ignored issues
–
show
It seems like
$this->skipCounts can also be of type boolean ; however, parameter $array of end() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
289 | } |
||||
290 | |||||
291 | /** |
||||
292 | * @return float|int |
||||
293 | */ |
||||
294 | 2 | public function getElapsedTime() |
|||
295 | { |
||||
296 | 2 | if (end($this->timers)) { |
|||
0 ignored issues
–
show
It seems like
$this->timers can also be of type boolean ; however, parameter $array of end() does only seem to accept array , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
297 | 2 | return $this->getMicrotime() - end($this->timers); |
|||
298 | } |
||||
299 | |||||
300 | return 0; |
||||
301 | } |
||||
302 | |||||
303 | /** |
||||
304 | * @return float |
||||
305 | */ |
||||
306 | 2 | private function getMicrotime() |
|||
307 | { |
||||
308 | 2 | [$usec, $sec] = explode(' ', microtime()); |
|||
309 | |||||
310 | 2 | return (float) $usec + (float) $sec; |
|||
311 | } |
||||
312 | } |
||||
313 |