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 XML output of the test to a specified Writer
22
 *
23
 * @author  Michiel Rook <mrook@php.net>
24
 * @package phing.tasks.ext.formatter
25
 * @since   2.1.0
26
 */
27
class XMLPHPUnitResultFormatter7 extends PHPUnitResultFormatter7
28
{
29
    /**
30
     * @var JUnit
31
     */
32
    private $logger = null;
33

34
    /**
35
     * @param PHPUnitTask $parentTask
36
     */
37 1
    public function __construct(PHPUnitTask $parentTask)
38
    {
39 1
        parent::__construct($parentTask);
40

41 1
        $logIncompleteSkipped = $parentTask->getHaltonincomplete() || $parentTask->getHaltonskipped();
42

43 1
        $this->logger = new JUnit(null, $logIncompleteSkipped);
44 1
        $this->logger->setWriteDocument(false);
45
    }
46

47
    /**
48
     * @return string
49
     */
50 0
    public function getExtension()
51
    {
52 0
        return ".xml";
53
    }
54

55
    /**
56
     * @return string
57
     */
58 0
    public function getPreferredOutfile()
59
    {
60 0
        return "testsuites";
61
    }
62

63
    /**
64
     * @param PHPUnit\Framework\TestSuite $suite
65
     */
66 1
    public function startTestSuite(PHPUnit\Framework\TestSuite $suite): void
67
    {
68 1
        parent::startTestSuite($suite);
69

70 1
        $this->logger->startTestSuite($suite);
71
    }
72

73
    /**
74
     * @param PHPUnit\Framework\TestSuite $suite
75
     */
76 1
    public function endTestSuite(PHPUnit\Framework\TestSuite $suite): void
77
    {
78 1
        parent::endTestSuite($suite);
79

80 1
        $this->logger->endTestSuite($suite);
81
    }
82

83
    /**
84
     * @param PHPUnit\Framework\Test $test
85
     */
86 1
    public function startTest(PHPUnit\Framework\Test $test): void
87
    {
88 1
        parent::startTest($test);
89

90 1
        $this->logger->startTest($test);
91
    }
92

93
    /**
94
     * @param PHPUnit\Framework\Test $test
95
     * @param float $time
96
     */
97 1
    public function endTest(PHPUnit\Framework\Test $test, float $time): void
98
    {
99 1
        parent::endTest($test, $time);
100

101 1
        $this->logger->endTest($test, $time);
102
    }
103

104
    /**
105
     * @param PHPUnit\Framework\Test $test
106
     * @param Exception $e
107
     * @param float $time
108
     */
109 0
    public function addError(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
110
    {
111 0
        parent::addError($test, $e, $time);
112

113 0
        $this->logger->addError($test, $e, $time);
114
    }
115

116
    /**
117
     * @param PHPUnit\Framework\Test $test
118
     * @param PHPUnit\Framework\AssertionFailedError $e
119
     * @param float $time
120
     */
121 0
    public function addFailure(
122
        PHPUnit\Framework\Test $test,
123
        PHPUnit\Framework\AssertionFailedError $e,
124
        float $time
125
    ): void {
126 0
        parent::addFailure($test, $e, $time);
127

128 0
        $this->logger->addFailure($test, $e, $time);
129
    }
130

131
    /**
132
     * @param PHPUnit\Framework\Test $test
133
     * @param PHPUnit\Framework\AssertionFailedError $e
134
     * @param float $time
135
     */
136 0
    public function addWarning(PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, float $time): void
137
    {
138 0
        parent::addWarning($test, $e, $time);
139

140 0
        $this->logger->addWarning($test, $e, $time);
141
    }
142

143
    /**
144
     * @param PHPUnit\Framework\Test $test
145
     * @param Exception $e
146
     * @param float $time
147
     */
148 0
    public function addIncompleteTest(PHPUnit\Framework\Test $test, Throwable $e, float $time): void
149
    {
150 0
        parent::addIncompleteTest($test, $e, $time);
151

152 0
        $this->logger->addIncompleteTest($test, $e, $time);
153
    }
154

155 1
    public function endTestRun()
156
    {
157 1
        parent::endTestRun();
158

159 1
        if ($this->out) {
160 1
            $this->out->write($this->logger->getXML());
161 1
            $this->out->close();
162
        }
163
    }
164
}

Read our documentation on viewing source code .

Loading