Ticket #254: SimpleTestDebugResultFormatter.php

File SimpleTestDebugResultFormatter.php, 3.5 KB (added by tarjei@…, 3 years ago)
Line 
1<?php
2/**
3 * $Id: SimpleTestPlainResultFormatter.php 284 2007-11-03 08:57:48Z hans $
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 'phing/tasks/ext/simpletest/SimpleTestResultFormatter.php';
23
24/**
25 * Prints plain text output of the test to a specified Writer.
26 *
27 * @author Michiel Rook <michiel.rook@gmail.com>
28 * @version $Id: SimpleTestPlainResultFormatter.php 284 2007-11-03 08:57:48Z hans $
29 * @package phing.tasks.ext.simpletest
30 * @since 2.2.0
31 */
32class SimpleTestDebugResultFormatter extends SimpleTestResultFormatter
33{
34    protected $current_case = "";
35    protected $current_test = "";
36    private $failingTests = array();
37
38    function printFailingTests()  {
39        foreach ($this->failingTests as $test) {
40            $this->out->write($test . "\n");
41        }
42    }
43
44    function paintCaseStart($test_name)
45    {
46        parent::paintCaseStart($test_name);
47        $this->paint( "Testsuite: $test_name\n");
48        $this->current_case = $test_name;
49    }
50    function paintMethodStart($test_name)
51    {
52        parent::paintMethodStart($test_name);
53        $this->current_test = $test_name;
54        //$msg = "{$this->current_case} :: $test_name\n";
55        $msg = "    TestCase: $test_name";
56        $this->paint($msg);
57    }
58
59    function paint($msg) {
60        if ($this->out == null ) {
61            print $msg;
62        } else {
63            $this->out->write($msg);
64        }
65
66
67    }
68
69    function paintMethodEnd($test_name) {
70        parent::paintMethodEnd($test_name);
71        $this->paint("\n");
72
73    }
74   
75    function paintCaseEnd($test_name)
76    {
77        parent::paintCaseEnd($test_name);
78        $this->current_case = "";
79        /* Only count suites where more than one test was run */
80        if ($this->getRunCount() && false)
81        {
82            $sb.= "Tests run: " . $this->getRunCount();
83            $sb.= ", Failures: " . $this->getFailureCount();
84            $sb.= ", Errors: " . $this->getErrorCount();
85            $sb.= ", Time elapsed: " . $this->getElapsedTime();
86            $sb.= " sec\n";
87            $this->paint($sb);
88        }
89
90    }
91
92    function paintError($message)
93    {
94        parent::paintError($message);
95        $this->formatError("ERROR", $message);
96        $this->failingTests[] = $this->current_case . "->" . $this->current_test;
97    }
98
99    function paintFail($message)
100    {
101        parent::paintFail($message);
102        $this->formatError("FAILED", $message);
103        $this->failingTests[] = $this->current_case . "->" . $this->current_test;
104    }
105    function paintException($message)
106    {
107        parent::paintException($message);
108       
109        $this->failingTests[] = $this->current_case . "->" . $this->current_test;
110        $this->formatError("Exception", $message);
111    }
112
113
114
115    private function formatError($type, $message)
116    {
117
118        $this->paint("ERROR: $type: $message");
119    }
120
121}
122?>