source: trunk/classes/phing/tasks/ext/phpunit/formatter/XMLPHPUnitResultFormatter.php @ 554

Revision 554, 3.2 KB checked in by mrook, 13 months ago (diff)

Move formatters to appropriately named directory

Line 
1<?php
2/**
3 * $Id: XMLPHPUnitResultFormatter.php -1   $
4 *
5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 *
17 * This software consists of voluntary contributions made by many individuals
18 * and is licensed under the LGPL. For more information please see
19 * <http://phing.info>.
20 */
21
22require_once 'PHPUnit/Util/Log/XML.php';
23
24require_once 'phing/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php';
25
26/**
27 * Prints XML output of the test to a specified Writer
28 *
29 * @author Michiel Rook <michiel.rook@gmail.com>
30 * @version $Id: XMLPHPUnitResultFormatter.php -1   $
31 * @package phing.tasks.ext.formatter
32 * @since 2.1.0
33 */
34class XMLPHPUnitResultFormatter extends PHPUnitResultFormatter
35{
36    /**
37     * @var PHPUnit_Util_Log_XML
38     */
39    private $logger = NULL;
40
41    function __construct()
42    {
43        $this->logger = new PHPUnit_Util_Log_XML(null, true);
44        $this->logger->setWriteDocument(false);
45    }
46
47    function getExtension()
48    {
49        return ".xml";
50    }
51
52    function getPreferredOutfile()
53    {
54        return "testsuites";
55    }
56
57    function startTestSuite(PHPUnit_Framework_TestSuite $suite)
58    {
59        parent::startTestSuite($suite);
60
61        $this->logger->startTestSuite($suite);
62    }
63
64    function endTestSuite(PHPUnit_Framework_TestSuite $suite)
65    {
66        parent::endTestSuite($suite);
67
68        $this->logger->endTestSuite($suite);
69    }
70
71    function startTest(PHPUnit_Framework_Test $test)
72    {
73        parent::startTest($test);
74
75        $this->logger->startTest($test);
76    }
77
78    function endTest(PHPUnit_Framework_Test $test, $time)
79    {
80        parent::endTest($test, $time);
81
82        $this->logger->endTest($test, $time);
83    }
84
85    function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
86    {
87        parent::addError($test, $e, $time);
88
89        $this->logger->addError($test, $e, $time);
90    }
91
92    function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
93    {
94        parent::addFailure($test, $e, $time);
95
96        $this->logger->addFailure($test, $e, $time);
97    }
98
99    function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
100    {
101        parent::addIncompleteTest($test, $e, $time);
102
103        $this->logger->addIncompleteTest($test, $e, $time);
104    }
105
106    function endTestRun()
107    {
108        parent::endTestRun();
109
110        if ($this->out)
111        {
112            $this->out->write($this->logger->getXML());
113            $this->out->close();
114        }
115    }
116}
Note: See TracBrowser for help on using the repository browser.