5 * Copyright (c) 2002-2011, Sebastian Bergmann <sebastian@phpunit.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.
38 * @subpackage Util_TestDox
39 * @author Sebastian Bergmann <sebastian@phpunit.de>
40 * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.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
47 * Base class for printers of TestDox documentation.
50 * @subpackage Util_TestDox
51 * @author Sebastian Bergmann <sebastian@phpunit.de>
52 * @copyright 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
53 * @license http://www.opensource.org/licenses/bsd-license.php BSD License
54 * @version Release: 3.5.14
55 * @link http://www.phpunit.de/
56 * @since Class available since Release 2.1.0
58 abstract class PHPUnit_Util_TestDox_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
61 * @var PHPUnit_Util_TestDox_NamePrettifier
63 protected $prettifier;
68 protected $testClass = '';
73 protected $testStatus = FALSE;
78 protected $tests = array();
83 protected $successful = 0;
88 protected $failed = 0;
93 protected $skipped = 0;
98 protected $incomplete = 0;
103 protected $testTypeOfInterest = 'PHPUnit_Framework_TestCase';
108 protected $currentTestClassPrettified;
113 protected $currentTestMethodPrettified;
118 * @param resource $out
120 public function __construct($out = NULL)
122 parent::__construct($out);
124 $this->prettifier = new PHPUnit_Util_TestDox_NamePrettifier;
129 * Flush buffer and close output.
132 public function flush()
143 * @param PHPUnit_Framework_Test $test
144 * @param Exception $e
147 public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
149 if ($test instanceof $this->testTypeOfInterest) {
150 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
156 * A failure occurred.
158 * @param PHPUnit_Framework_Test $test
159 * @param PHPUnit_Framework_AssertionFailedError $e
162 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
164 if ($test instanceof $this->testTypeOfInterest) {
165 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
173 * @param PHPUnit_Framework_Test $test
174 * @param Exception $e
177 public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
179 if ($test instanceof $this->testTypeOfInterest) {
180 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
188 * @param PHPUnit_Framework_Test $test
189 * @param Exception $e
191 * @since Method available since Release 3.0.0
193 public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
195 if ($test instanceof $this->testTypeOfInterest) {
196 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
202 * A testsuite started.
204 * @param PHPUnit_Framework_TestSuite $suite
205 * @since Method available since Release 2.2.0
207 public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
214 * @param PHPUnit_Framework_TestSuite $suite
215 * @since Method available since Release 2.2.0
217 public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
224 * @param PHPUnit_Framework_Test $test
226 public function startTest(PHPUnit_Framework_Test $test)
228 if ($test instanceof $this->testTypeOfInterest) {
229 $class = get_class($test);
231 if ($this->testClass != $class) {
232 if ($this->testClass != '') {
236 $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
237 $this->startClass($class);
239 $this->testClass = $class;
240 $this->tests = array();
245 if ($test instanceof PHPUnit_Framework_TestCase &&
246 !$test instanceof PHPUnit_Framework_Warning) {
247 $annotations = $test->getAnnotations();
249 if (isset($annotations['method']['testdox'][0])) {
250 $this->currentTestMethodPrettified = $annotations['method']['testdox'][0];
256 $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(FALSE));
259 $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
266 * @param PHPUnit_Framework_Test $test
269 public function endTest(PHPUnit_Framework_Test $test, $time)
271 if ($test instanceof $this->testTypeOfInterest) {
272 if (!isset($this->tests[$this->currentTestMethodPrettified])) {
273 if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
274 $this->tests[$this->currentTestMethodPrettified]['success'] = 1;
275 $this->tests[$this->currentTestMethodPrettified]['failure'] = 0;
277 $this->tests[$this->currentTestMethodPrettified]['success'] = 0;
278 $this->tests[$this->currentTestMethodPrettified]['failure'] = 1;
281 if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
282 $this->tests[$this->currentTestMethodPrettified]['success']++;
284 $this->tests[$this->currentTestMethodPrettified]['failure']++;
288 $this->currentTestClassPrettified = NULL;
289 $this->currentTestMethodPrettified = NULL;
294 * @since Method available since Release 2.3.0
296 protected function doEndClass()
298 foreach ($this->tests as $name => $data) {
299 $this->onTest($name, $data['failure'] == 0);
302 $this->endClass($this->testClass);
306 * Handler for 'start run' event.
309 protected function startRun()
314 * Handler for 'start class' event.
316 * @param string $name
318 protected function startClass($name)
323 * Handler for 'on test' event.
325 * @param string $name
326 * @param boolean $success
328 protected function onTest($name, $success = TRUE)
333 * Handler for 'end class' event.
335 * @param string $name
337 protected function endClass($name)
342 * Handler for 'end run' event.
345 protected function endRun()