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 <siad.ardroumli@gmail.com>
24
 * @package phing.tasks.ext.phpunit.formatter
25
 */
26
abstract class PHPUnitResultFormatter7 implements PHPUnit\Framework\TestListener
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

68
    /**
69
     * Constructor
70
     *
71
     * @param PHPUnitTask $parentTask Calling Task
72
     */
73 1
    public function __construct(PHPUnitTask $parentTask)
74
    {
75 1
        $this->project = $parentTask->getProject();
76
    }
77

78
    /**
79
     * Sets the writer the formatter is supposed to write its results to.
80
     *
81
     * @param Writer $out
82
     */
83 1
    public function setOutput(Writer $out)
84
    {
85 1
        $this->out = $out;
86
    }
87

88
    /**
89
     * Returns the extension used for this formatter
90
     *
91
     * @return string the extension
92
     */
93 0
    public function getExtension()
94
    {
95 0
        return '';
96
    }
97

98
    /**
99
     * @return string
100
     */
101 0
    public function getPreferredOutfile()
102
    {
103 0
        return '';
104
    }
105

106
    /**
107
     * @param PHPUnit\Framework\TestResult $result
108
     */
109 1
    public function processResult(PHPUnit\Framework\TestResult $result)
110
    {
111
    }
112

113 1
    public function startTestRun()
114
    {
115 1
        $this->timers = [$this->getMicrotime()];
116 1
        $this->runCounts = [0];
117 1
        $this->failureCounts = [0];
118 1
        $this->errorCounts = [0];
119 1
        $this->warningCounts = [0];
120 1
        $this->incompleteCounts = [0];
121 1
        $this->skipCounts = [0];
122
    }
123

124 1
    public function endTestRun()
125
    {
126
    }
127

128
    /**
129
     * @param PHPUnit\Framework\TestSuite $suite
130
     */
131 1
    public function startTestSuite(PHPUnit\Framework\TestSuite $suite): void
132
    {
133 1
        $this->timers[] = $this->getMicrotime();
134 1
        $this->runCounts[] = 0;
135 1
        $this->failureCounts[] = 0;
136 1
        $this->errorCounts[] = 0;
137 1
        $this->incompleteCounts[] = 0;
138 1
        $this->skipCounts[] = 0;
139
    }
140

141
    /**
142
     * @param PHPUnit\Framework\TestSuite $suite
143
     */
144 1
    public function endTestSuite(PHPUnit\Framework\TestSuite $suite): void
145
    {
146 1
        $lastRunCount = array_pop($this->runCounts);
147 1
        $this->runCounts[count($this->runCounts) - 1] += $lastRunCount;
148

149 1
        $lastFailureCount = array_pop($this->failureCounts);
150 1
        $this->failureCounts[count($this->failureCounts) - 1] += $lastFailureCount;
151

152 1
        $lastErrorCount = array_pop($this->errorCounts);
153 1
        $this->errorCounts[count($this->errorCounts) - 1] += $lastErrorCount;
154

155 1
        $lastIncompleteCount = array_pop($this->incompleteCounts);
156 1
        $this->incompleteCounts[count($this->incompleteCounts) - 1] += $lastIncompleteCount;
157

158 1
        $lastSkipCount = array_pop($this->skipCounts);
159 1
        $this->skipCounts[count($this->skipCounts) - 1] += $lastSkipCount;
160

161 1
        array_pop($this->timers);
162
    }
163

164
    /**
165
     * @param PHPUnit\Framework\Test $test
166
     */
167 1
    public function startTest(PHPUnit\Framework\Test $test): void
168
    {
169 1
        $this->runCounts[count($this->runCounts) - 1]++;
170
    }
171

172
    /**
173
     * @param PHPUnit\Framework\Test $test
174
     * @param float $time
175
     */
176 1
    public function endTest(PHPUnit\Framework\Test $test, float $time): void
177
    {
178
    }
179

180
    /**
181
     * @param PHPUnit\Framework\Test $test
182
     * @param Exception $e
183
     * @param float $time
184
     */
185 0
    public function addError(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
186
    {
187 0
        $this->errorCounts[count($this->errorCounts) - 1]++;
188
    }
189

190
    /**
191
     * @param PHPUnit\Framework\Test $test
192
     * @param PHPUnit\Framework\AssertionFailedError $e
193
     * @param float $time
194
     */
195 1
    public function addFailure(
196
        PHPUnit\Framework\Test $test,
197
        PHPUnit\Framework\AssertionFailedError $e,
198
        float $time
199
    ): void {
200 1
        $this->failureCounts[count($this->failureCounts) - 1]++;
201
    }
202

203
    /**
204
     * @param PHPUnit\Framework\Test $test
205
     * @param PHPUnit\Framework\Warning $e
206
     * @param float $time
207
     */
208 0
    public function addWarning(PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void
209
    {
210 0
        $this->warningCounts[count($this->warningCounts) - 1]++;
211
    }
212

213
    /**
214
     * @param PHPUnit\Framework\Test $test
215
     * @param Exception $e
216
     * @param float $time
217
     */
218 0
    public function addIncompleteTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
219
    {
220 0
        $this->incompleteCounts[count($this->incompleteCounts) - 1]++;
221
    }
222

223
    /**
224
     * @param PHPUnit\Framework\Test $test
225
     * @param Exception $e
226
     * @param float $time
227
     */
228 0
    public function addSkippedTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
229
    {
230 0
        $this->skipCounts[count($this->skipCounts) - 1]++;
231
    }
232

233
    /**
234
     * @param PHPUnit\Framework\Test $test
235
     * @param Exception $e
236
     * @param float $time
237
     */
238 0
    public function addRiskyTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
239
    {
240
    }
241

242
    /**
243
     * @return mixed
244
     */
245 1
    public function getRunCount()
246
    {
247 1
        return end($this->runCounts);
248
    }
249

250
    /**
251
     * @return mixed
252
     */
253 1
    public function getFailureCount()
254
    {
255 1
        return end($this->failureCounts);
256
    }
257

258
    /**
259
     * @return mixed
260
     */
261 1
    public function getWarningCount()
262
    {
263 1
        return end($this->warningCounts);
264
    }
265

266
    /**
267
     * @return mixed
268
     */
269 1
    public function getErrorCount()
270
    {
271 1
        return end($this->errorCounts);
272
    }
273

274
    /**
275
     * @return mixed
276
     */
277 1
    public function getIncompleteCount()
278
    {
279 1
        return end($this->incompleteCounts);
280
    }
281

282
    /**
283
     * @return mixed
284
     */
285 1
    public function getSkippedCount()
286
    {
287 1
        return end($this->skipCounts);
288
    }
289

290
    /**
291
     * @return float|int
292
     */
293 1
    public function getElapsedTime()
294
    {
295 1
        if (end($this->timers)) {
296 1
            return $this->getMicrotime() - end($this->timers);
297
        }
298

299 0
        return 0;
300
    }
301

302
    /**
303
     * @return float
304
     */
305 1
    private function getMicrotime()
306
    {
307 1
        [$usec, $sec] = explode(' ', microtime());
308

309 1
        return (float) $usec + (float) $sec;
310
    }
311
}

Read our documentation on viewing source code .

Loading