Passed
Push — master ( 6f18ed...823d8f )
by Siad
10:47
created

PHPUnitResultFormatter7::getRiskyCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
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
/**
21
 * This abstract class describes classes that format the results of a PHPUnit testrun.
22
 *
23
 * @author  Siad Ardroumli <[email protected]>
24
 * @package phing.tasks.ext.phpunit.formatter
25
 */
26
abstract class PHPUnitResultFormatter7 implements PHPUnit\Framework\TestListener
0 ignored issues
show
Deprecated Code introduced by
The interface PHPUnit\Framework\TestListener has been deprecated: Use the `TestHook` interfaces instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

26
abstract class PHPUnitResultFormatter7 implements /** @scrutinizer ignore-deprecated */ PHPUnit\Framework\TestListener

This interface has been deprecated. The supplier of the interface has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.

Loading history...
27
{
28
    protected $out;
29
30
    /** @var Project */
31
    protected $project;
32
33
    /**
34
     * @var array
35
     */
36
    private $timers = [];
37
38
    /**
39
     * @var array
40
     */
41
    private $runCounts = [];
42
43
    /**
44
     * @var array
45
     */
46
    private $failureCounts = [];
47
48
    /**
49
     * @var array
50
     */
51
    private $errorCounts = [];
52
53
    /**
54
     * @var array
55
     */
56
    private $incompleteCounts = [];
57
58
    /**
59
     * @var array
60
     */
61
    private $skipCounts = [];
62
63
    /**
64
     * @var array
65
     */
66
    private $warningCounts = [];
67
    private $riskyCounts = [];
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)
0 ignored issues
show
Unused Code introduced by
The parameter $result is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

110
    public function processResult(/** @scrutinizer ignore-unused */ PHPUnit\Framework\TestResult $result)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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
        $this->riskyCounts = [0];
124 2
    }
125
126 2
    public function endTestRun()
127
    {
128 2
    }
129
130
    /**
131
     * @param PHPUnit\Framework\TestSuite $suite
132
     */
133 2
    public function startTestSuite(PHPUnit\Framework\TestSuite $suite): void
134
    {
135 2
        $this->timers[] = $this->getMicrotime();
136 2
        $this->runCounts[] = 0;
137 2
        $this->failureCounts[] = 0;
138 2
        $this->errorCounts[] = 0;
139 2
        $this->incompleteCounts[] = 0;
140 2
        $this->skipCounts[] = 0;
141 2
        $this->warningCounts[] = 0;
142 2
        $this->riskyCounts[] = 0;
143 2
    }
144
145
    /**
146
     * @param PHPUnit\Framework\TestSuite $suite
147
     */
148 2
    public function endTestSuite(PHPUnit\Framework\TestSuite $suite): void
149
    {
150 2
        $lastRunCount = array_pop($this->runCounts);
151 2
        $this->runCounts[count($this->runCounts) - 1] += $lastRunCount;
152
153 2
        $lastFailureCount = array_pop($this->failureCounts);
154 2
        $this->failureCounts[count($this->failureCounts) - 1] += $lastFailureCount;
155
156 2
        $lastErrorCount = array_pop($this->errorCounts);
157 2
        $this->errorCounts[count($this->errorCounts) - 1] += $lastErrorCount;
158
159 2
        $lastIncompleteCount = array_pop($this->incompleteCounts);
160 2
        $this->incompleteCounts[count($this->incompleteCounts) - 1] += $lastIncompleteCount;
161
162 2
        $lastSkipCount = array_pop($this->skipCounts);
163 2
        $this->skipCounts[count($this->skipCounts) - 1] += $lastSkipCount;
164
165 2
        $lastWarningCount = array_pop($this->warningCounts);
166 2
        $this->warningCounts[count($this->warningCounts) - 1] += $lastWarningCount;
167
168 2
        $lastRiskyCount = array_pop($this->riskyCounts);
169 2
        $this->riskyCounts[count($this->riskyCounts) - 1] += $lastRiskyCount;
170
171 2
        array_pop($this->timers);
172 2
    }
173
174
    /**
175
     * @param PHPUnit\Framework\Test $test
176
     */
177 2
    public function startTest(PHPUnit\Framework\Test $test): void
178
    {
179 2
        $this->runCounts[count($this->runCounts) - 1]++;
180 2
    }
181
182
    /**
183
     * @param PHPUnit\Framework\Test $test
184
     * @param float $time
185
     */
186 2
    public function endTest(PHPUnit\Framework\Test $test, float $time): void
187
    {
188 2
    }
189
190
    /**
191
     * @param PHPUnit\Framework\Test $test
192
     * @param Exception $e
193
     * @param float $time
194
     */
195
    public function addError(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
196
    {
197
        $this->errorCounts[count($this->errorCounts) - 1]++;
198
    }
199
200
    /**
201
     * @param PHPUnit\Framework\Test $test
202
     * @param PHPUnit\Framework\AssertionFailedError $e
203
     * @param float $time
204
     */
205 1
    public function addFailure(
206
        PHPUnit\Framework\Test $test,
207
        PHPUnit\Framework\AssertionFailedError $e,
208
        float $time
209
    ): void {
210 1
        $this->failureCounts[count($this->failureCounts) - 1]++;
211 1
    }
212
213
    /**
214
     * @param PHPUnit\Framework\Test $test
215
     * @param PHPUnit\Framework\Warning $e
216
     * @param float $time
217
     */
218
    public function addWarning(PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void
219
    {
220
        $this->warningCounts[count($this->warningCounts) - 1]++;
221
    }
222
223
    /**
224
     * @param PHPUnit\Framework\Test $test
225
     * @param Exception $e
226
     * @param float $time
227
     */
228
    public function addIncompleteTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
229
    {
230
        $this->incompleteCounts[count($this->incompleteCounts) - 1]++;
231
    }
232
233
    /**
234
     * @param PHPUnit\Framework\Test $test
235
     * @param Exception $e
236
     * @param float $time
237
     */
238
    public function addSkippedTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
239
    {
240
        $this->skipCounts[count($this->skipCounts) - 1]++;
241
    }
242
243
    /**
244
     * @param PHPUnit\Framework\Test $test
245
     * @param Exception $e
246
     * @param float $time
247
     */
248
    public function addRiskyTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
249
    {
250
        $this->riskyCounts[count($this->riskyCounts) - 1]++;
251
    }
252
253
    /**
254
     * @return mixed
255
     */
256 2
    public function getRunCount()
257
    {
258 2
        return end($this->runCounts);
259
    }
260
261
    /**
262
     * @return mixed
263
     */
264 2
    public function getFailureCount()
265
    {
266 2
        return end($this->failureCounts);
267
    }
268
269
    /**
270
     * @return mixed
271
     */
272 2
    public function getWarningCount()
273
    {
274 2
        return end($this->warningCounts);
275
    }
276
277
    /**
278
     * @return mixed
279
     */
280
    public function getRiskyCount()
281
    {
282
        return end($this->riskyCounts);
283
    }
284
285
    /**
286
     * @return mixed
287
     */
288 2
    public function getErrorCount()
289
    {
290 2
        return end($this->errorCounts);
291
    }
292
293
    /**
294
     * @return mixed
295
     */
296 2
    public function getIncompleteCount()
297
    {
298 2
        return end($this->incompleteCounts);
299
    }
300
301
    /**
302
     * @return mixed
303
     */
304 2
    public function getSkippedCount()
305
    {
306 2
        return end($this->skipCounts);
307
    }
308
309
    /**
310
     * @return float|int
311
     */
312 2
    public function getElapsedTime()
313
    {
314 2
        if (end($this->timers)) {
315 2
            return $this->getMicrotime() - end($this->timers);
316
        }
317
318
        return 0;
319
    }
320
321
    /**
322
     * @return float
323
     */
324 2
    private function getMicrotime()
325
    {
326 2
        [$usec, $sec] = explode(' ', microtime());
327
328 2
        return (float) $usec + (float) $sec;
329
    }
330
}
331