Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/**
3
 * PHPUnit
4
 *
5
 * Copyright (c) 2002-2010, Sebastian Bergmann <sb@sebastian-bergmann.de>.
6
 * All rights reserved.
7
 *
8
 * Redistribution and use in source and binary forms, with or without
9
 * modification, are permitted provided that the following conditions
10
 * are met:
11
 *
12
 *   * Redistributions of source code must retain the above copyright
13
 *     notice, this list of conditions and the following disclaimer.
14
 *
15
 *   * Redistributions in binary form must reproduce the above copyright
16
 *     notice, this list of conditions and the following disclaimer in
17
 *     the documentation and/or other materials provided with the
18
 *     distribution.
19
 *
20
 *   * Neither the name of Sebastian Bergmann nor the names of his
21
 *     contributors may be used to endorse or promote products derived
22
 *     from this software without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35
 * POSSIBILITY OF SUCH DAMAGE.
36
 *
37
 * @category   Testing
38
 * @package    PHPUnit
39
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
40
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
41
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
42
 * @link       http://www.phpunit.de/
43
 * @since      File available since Release 2.3.0
44
 */
45
 
46
require_once 'PHPUnit/Framework.php';
47
require_once 'PHPUnit/Util/Filter.php';
48
require_once 'PHPUnit/Util/TestDox/NamePrettifier.php';
49
require_once 'PHPUnit/Util/Printer.php';
50
 
51
PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
52
 
53
/**
54
 * Base class for printers of TestDox documentation.
55
 *
56
 * @category   Testing
57
 * @package    PHPUnit
58
 * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
59
 * @copyright  2002-2010 Sebastian Bergmann <sb@sebastian-bergmann.de>
60
 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
61
 * @version    Release: 3.4.15
62
 * @link       http://www.phpunit.de/
63
 * @since      Class available since Release 2.1.0
64
 */
65
abstract class PHPUnit_Util_TestDox_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
66
{
67
    /**
68
     * @var    PHPUnit_Util_TestDox_NamePrettifier
69
     */
70
    protected $prettifier;
71
 
72
    /**
73
     * @var    string
74
     */
75
    protected $testClass = '';
76
 
77
    /**
78
     * @var    integer
79
     */
80
    protected $testStatus = FALSE;
81
 
82
    /**
83
     * @var    array
84
     */
85
    protected $tests = array();
86
 
87
    protected $successful = 0;
88
    protected $failed = 0;
89
    protected $skipped = 0;
90
    protected $incomplete = 0;
91
    protected $testTypeOfInterest = 'PHPUnit_Framework_TestCase';
92
 
93
    /**
94
     * @var    string
95
     */
96
    protected $currentTestClassPrettified;
97
 
98
    /**
99
     * @var    string
100
     */
101
    protected $currentTestMethodPrettified;
102
 
103
    /**
104
     * Constructor.
105
     *
106
     * @param  resource  $out
107
     */
108
    public function __construct($out = NULL)
109
    {
110
        parent::__construct($out);
111
 
112
        $this->prettifier = new PHPUnit_Util_TestDox_NamePrettifier;
113
        $this->startRun();
114
    }
115
 
116
    /**
117
     * Flush buffer and close output.
118
     *
119
     */
120
    public function flush()
121
    {
122
        $this->doEndClass();
123
        $this->endRun();
124
 
125
        parent::flush();
126
    }
127
 
128
    /**
129
     * An error occurred.
130
     *
131
     * @param  PHPUnit_Framework_Test $test
132
     * @param  Exception              $e
133
     * @param  float                  $time
134
     */
135
    public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
136
    {
137
        if ($test instanceof $this->testTypeOfInterest) {
138
            $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
139
            $this->failed++;
140
        }
141
    }
142
 
143
    /**
144
     * A failure occurred.
145
     *
146
     * @param  PHPUnit_Framework_Test                 $test
147
     * @param  PHPUnit_Framework_AssertionFailedError $e
148
     * @param  float                                  $time
149
     */
150
    public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
151
    {
152
        if ($test instanceof $this->testTypeOfInterest) {
153
            $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
154
            $this->failed++;
155
        }
156
    }
157
 
158
    /**
159
     * Incomplete test.
160
     *
161
     * @param  PHPUnit_Framework_Test $test
162
     * @param  Exception              $e
163
     * @param  float                  $time
164
     */
165
    public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
166
    {
167
        if ($test instanceof $this->testTypeOfInterest) {
168
            $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
169
            $this->incomplete++;
170
        }
171
    }
172
 
173
    /**
174
     * Skipped test.
175
     *
176
     * @param  PHPUnit_Framework_Test $test
177
     * @param  Exception              $e
178
     * @param  float                  $time
179
     * @since  Method available since Release 3.0.0
180
     */
181
    public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
182
    {
183
        if ($test instanceof $this->testTypeOfInterest) {
184
            $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
185
            $this->skipped++;
186
        }
187
    }
188
 
189
    /**
190
     * A testsuite started.
191
     *
192
     * @param  PHPUnit_Framework_TestSuite $suite
193
     * @since  Method available since Release 2.2.0
194
     */
195
    public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
196
    {
197
    }
198
 
199
    /**
200
     * A testsuite ended.
201
     *
202
     * @param  PHPUnit_Framework_TestSuite $suite
203
     * @since  Method available since Release 2.2.0
204
     */
205
    public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
206
    {
207
    }
208
 
209
    /**
210
     * A test started.
211
     *
212
     * @param  PHPUnit_Framework_Test $test
213
     */
214
    public function startTest(PHPUnit_Framework_Test $test)
215
    {
216
        if ($test instanceof $this->testTypeOfInterest) {
217
            $class = get_class($test);
218
 
219
            if ($this->testClass != $class) {
220
                if ($this->testClass != '') {
221
                    $this->doEndClass();
222
                }
223
 
224
                $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
225
                $this->startClass($class);
226
 
227
                $this->testClass = $class;
228
                $this->tests     = array();
229
            }
230
 
231
            $prettified = FALSE;
232
 
233
            if ($test instanceof PHPUnit_Framework_TestCase &&
234
               !$test instanceof PHPUnit_Framework_Warning) {
235
                $annotations = $test->getAnnotations();
236
 
237
                if (isset($annotations['method']['testdox'][0])) {
238
                    $this->currentTestMethodPrettified = $annotations['method']['testdox'][0];
239
                    $prettified = TRUE;
240
                }
241
            }
242
 
243
            if (!$prettified) {
244
                $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(FALSE));
245
            }
246
 
247
            $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
248
        }
249
    }
250
 
251
    /**
252
     * A test ended.
253
     *
254
     * @param  PHPUnit_Framework_Test $test
255
     * @param  float                  $time
256
     */
257
    public function endTest(PHPUnit_Framework_Test $test, $time)
258
    {
259
        if ($test instanceof $this->testTypeOfInterest) {
260
            if (!isset($this->tests[$this->currentTestMethodPrettified])) {
261
                if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
262
                    $this->tests[$this->currentTestMethodPrettified]['success'] = 1;
263
                    $this->tests[$this->currentTestMethodPrettified]['failure'] = 0;
264
                } else {
265
                    $this->tests[$this->currentTestMethodPrettified]['success'] = 0;
266
                    $this->tests[$this->currentTestMethodPrettified]['failure'] = 1;
267
                }
268
            } else {
269
                if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
270
                    $this->tests[$this->currentTestMethodPrettified]['success']++;
271
                } else {
272
                    $this->tests[$this->currentTestMethodPrettified]['failure']++;
273
                }
274
            }
275
 
276
            $this->currentTestClassPrettified  = NULL;
277
            $this->currentTestMethodPrettified = NULL;
278
        }
279
    }
280
 
281
    /**
282
     * @since  Method available since Release 2.3.0
283
     */
284
    protected function doEndClass()
285
    {
286
        foreach ($this->tests as $name => $data) {
287
            $this->onTest($name, $data['failure'] == 0);
288
        }
289
 
290
        $this->endClass($this->testClass);
291
    }
292
 
293
    /**
294
     * Handler for 'start run' event.
295
     *
296
     */
297
    protected function startRun()
298
    {
299
    }
300
 
301
    /**
302
     * Handler for 'start class' event.
303
     *
304
     * @param  string $name
305
     */
306
    protected function startClass($name)
307
    {
308
    }
309
 
310
    /**
311
     * Handler for 'on test' event.
312
     *
313
     * @param  string  $name
314
     * @param  boolean $success
315
     */
316
    protected function onTest($name, $success = TRUE)
317
    {
318
    }
319
 
320
    /**
321
     * Handler for 'end class' event.
322
     *
323
     * @param  string $name
324
     */
325
    protected function endClass($name)
326
    {
327
    }
328
 
329
    /**
330
     * Handler for 'end run' event.
331
     *
332
     */
333
    protected function endRun()
334
    {
335
    }
336
}
337
?>