Passed
Push — master ( 605b65...7a3d33 )
by Siad
09:53
created

CloverPHPUnitResultFormatter::endTestRun()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 12
rs 9.9666
c 0
b 0
f 0
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
 * Prints Clover XML output of the test
22
 *
23
 * @author  Siad Ardroumli <[email protected]>
24
 * @package phing.tasks.ext.formatter
25
 */
26
class CloverPHPUnitResultFormatter extends PHPUnitResultFormatter
27
{
28
    /**
29
     * @var PHPUnit\Framework\TestResult
30
     */
31
    private $result = null;
32
33
    /**
34
     * PHPUnit version
35
     *
36
     * @var string
37
     */
38
    private $version = null;
39
40
    /**
41
     * @param PHPUnitTask $parentTask
42
     */
43
    public function __construct(PHPUnitTask $parentTask)
44
    {
45
        parent::__construct($parentTask);
46
47
        $this->version = PHPUnit\Runner\Version::id();
48
    }
49
50
    /**
51
     * @return string
52
     */
53
    public function getExtension()
54
    {
55
        return ".xml";
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getPreferredOutfile()
62
    {
63
        return "clover-coverage";
64
    }
65
66
    /**
67
     * @param PHPUnit\Framework\TestResult $result
68
     */
69
    public function processResult(PHPUnit\Framework\TestResult $result)
70
    {
71
        $this->result = $result;
72
    }
73
74
    public function endTestRun()
75
    {
76
        $coverage = $this->result->getCodeCoverage();
77
78
        if (!empty($coverage)) {
79
            $cloverClass = '\SebastianBergmann\CodeCoverage\Report\Clover';
80
            $clover = new $cloverClass();
81
82
            $contents = $clover->process($coverage);
83
84
            if ($this->out) {
85
                $this->out->write($contents);
86
                $this->out->close();
87
            }
88
        }
89
90
        parent::endTestRun();
91
    }
92
}
93