. */ require_once 'phing/tasks/ext/phpunit/formatter/PHPUnitResultFormatter.php'; /** * Prints plain text output of the test to a specified Writer. * * @author Michiel Rook * @version $Id: PlainPHPUnitResultFormatter.php 905 2010-10-05 16:28:03Z mrook $ * @package phing.tasks.ext.phpunit.formatter * @since 2.1.0 */ class PlainPHPUnitResultFormatter extends PHPUnitResultFormatter { private $inner = ""; public function getExtension() { return ".txt"; } public function getPreferredOutfile() { return "testresults"; } public function startTestSuite(PHPUnit_Framework_TestSuite $suite) { parent::startTestSuite($suite); $this->inner = ""; } public function endTestSuite(PHPUnit_Framework_TestSuite $suite) { foreach ($suite->tests() as $test) { if ($test instanceof PHPUnit_Framework_TestSuite) { return false; } } $sb = "Testsuite: " . $suite->getName() . "\n"; $sb.= "Tests run: " . $this->getRunCount(); $sb.= ", Failures: " . $this->getFailureCount(); $sb.= ", Errors: " . $this->getErrorCount(); $sb.= ", Incomplete: " . $this->getIncompleteCount(); $sb.= ", Skipped: " . $this->getSkippedCount(); $sb.= ", Time elapsed: " . sprintf('%0.5f', $this->getElapsedTime()) . " s\n"; if ($this->out != NULL) { $this->out->write($sb); $this->out->write($this->inner); } parent::endTestSuite($suite); } public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { parent::addError($test, $e, $time); $this->formatError("ERROR", $test, $e); } public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { parent::addFailure($test, $e, $time); $this->formatError("FAILED", $test, $e); } public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { parent::addIncompleteTest($test, $e, $time); $this->formatError("INCOMPLETE", $test); } public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) { parent::addSkippedTest($test, $e, $time); $this->formatError("SKIPPED", $test); } private function formatError($type, PHPUnit_Framework_Test $test, Exception $e = null) { if ($test != null) { $this->endTest($test, time()); } $this->inner.= $test->getName() . " " . $type . "\n"; if ($e !== null) { $this->inner.= $e->getMessage() . "\n"; $this->inner.= PHPUnit_Util_Filter::getFilteredStackTrace($e, false) . "\n"; } } public function endTestRun() { parent::endTestRun(); if ($this->out != NULL) { $this->out->close(); } } }