5 * Copyright (c) 2002-2009, Sebastian Bergmann <sb@sebastian-bergmann.de>.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
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
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.
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.
39 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
40 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
41 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
43 * @link http://www.phpunit.de/
44 * @since File available since Release 2.3.0
47 require_once 'PHPUnit/Framework.php';
48 require_once 'PHPUnit/Util/Filter.php';
49 require_once 'PHPUnit/Util/TestDox/NamePrettifier.php';
50 require_once 'PHPUnit/Util/Printer.php';
52 PHPUnit_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT');
55 * Base class for printers of TestDox documentation.
59 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
60 * @copyright 2002-2009 Sebastian Bergmann <sb@sebastian-bergmann.de>
61 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
62 * @version Release: 3.3.17
63 * @link http://www.phpunit.de/
64 * @since Class available since Release 2.1.0
67 abstract class PHPUnit_Util_TestDox_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
70 * @var PHPUnit_Util_TestDox_NamePrettifier
72 protected $prettifier;
77 protected $testClass = '';
82 protected $testStatus = FALSE;
87 protected $tests = array();
89 protected $successful = 0;
90 protected $failed = 0;
91 protected $skipped = 0;
92 protected $incomplete = 0;
93 protected $testTypeOfInterest = 'PHPUnit_Framework_TestCase';
98 protected $currentTestClassPrettified;
103 protected $currentTestMethodPrettified;
108 * @param resource $out
110 public function __construct($out = NULL)
112 parent::__construct($out);
114 $this->prettifier = new PHPUnit_Util_TestDox_NamePrettifier;
119 * Flush buffer and close output.
122 public function flush()
133 * @param PHPUnit_Framework_Test $test
134 * @param Exception $e
137 public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
139 if ($test instanceof $this->testTypeOfInterest) {
140 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
146 * A failure occurred.
148 * @param PHPUnit_Framework_Test $test
149 * @param PHPUnit_Framework_AssertionFailedError $e
152 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
154 if ($test instanceof $this->testTypeOfInterest) {
155 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
163 * @param PHPUnit_Framework_Test $test
164 * @param Exception $e
167 public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
169 if ($test instanceof $this->testTypeOfInterest) {
170 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
178 * @param PHPUnit_Framework_Test $test
179 * @param Exception $e
181 * @since Method available since Release 3.0.0
183 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
185 if ($test instanceof $this->testTypeOfInterest) {
186 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
192 * A testsuite started.
194 * @param PHPUnit_Framework_TestSuite $suite
195 * @since Method available since Release 2.2.0
197 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
204 * @param PHPUnit_Framework_TestSuite $suite
205 * @since Method available since Release 2.2.0
207 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
214 * @param PHPUnit_Framework_Test $test
216 public function startTest(PHPUnit_Framework_Test $test)
218 if ($test instanceof $this->testTypeOfInterest) {
219 $class = get_class($test);
221 if ($this->testClass != $class) {
222 if ($this->testClass != '') {
226 $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
227 $this->startClass($class);
229 $this->testClass = $class;
230 $this->tests = array();
233 $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName());
234 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
241 * @param PHPUnit_Framework_Test $test
244 public function endTest(PHPUnit_Framework_Test $test, $time)
246 if ($test instanceof $this->testTypeOfInterest) {
247 if (!isset($this->tests[$this->currentTestMethodPrettified])) {
248 if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
249 $this->tests[$this->currentTestMethodPrettified]['success'] = 1;
250 $this->tests[$this->currentTestMethodPrettified]['failure'] = 0;
252 $this->tests[$this->currentTestMethodPrettified]['success'] = 0;
253 $this->tests[$this->currentTestMethodPrettified]['failure'] = 1;
256 if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
257 $this->tests[$this->currentTestMethodPrettified]['success']++;
259 $this->tests[$this->currentTestMethodPrettified]['failure']++;
263 $this->currentTestClassPrettified = NULL;
264 $this->currentTestMethodPrettified = NULL;
269 * @since Method available since Release 2.3.0
271 protected function doEndClass()
273 foreach ($this->tests as $name => $data) {
274 $this->onTest($name, $data['failure'] == 0);
277 $this->endClass($this->testClass);
281 * Handler for 'start run' event.
284 protected function startRun()
289 * Handler for 'start class' event.
291 * @param string $name
293 protected function startClass($name)
298 * Handler for 'on test' event.
300 * @param string $name
301 * @param boolean $success
303 protected function onTest($name, $success = TRUE)
308 * Handler for 'end class' event.
310 * @param string $name
312 protected function endClass($name)
317 * Handler for 'end run' event.
320 protected function endRun()