Permalink
Browse files

Show test suite hierarchy when running with --verbose.

  • Loading branch information...
1 parent abb5994 commit 7f40d8f431a0302397a7b4b2d68d336db5400a74 @sebastianbergmann committed Oct 5, 2006
Showing with 65 additions and 17 deletions.
  1. +65 −17 PHPUnit/TextUI/ResultPrinter.php
@@ -64,13 +64,30 @@
*/
class PHPUnit_TextUI_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
{
+ const EVENT_TEST_START = 0;
+ const EVENT_TEST_END = 1;
+ const EVENT_TESTSUITE_START = 2;
+ const EVENT_TESTSUITE_END = 3;
+
/**
* @var integer
* @access private
*/
private $column = 0;
/**
+ * @var integer
+ * @access private
+ */
+ private $depth = 0;
+
+ /**
+ * @var integer
+ * @access private
+ */
+ private $lastEvent = -1;
+
+ /**
* @var boolean
* @access private
*/
@@ -375,14 +392,12 @@ public function printWaitPrompt()
* An error occurred.
*
* @param PHPUnit_Framework_Test $test
- * @param Exception $e
+ * @param Exception $e
* @access public
*/
public function addError(PHPUnit_Framework_Test $test, Exception $e)
{
- $this->write('E');
- $this->nextColumn();
-
+ $this->writeProgress('E');
$this->lastTestFailed = TRUE;
}
@@ -395,9 +410,7 @@ public function addError(PHPUnit_Framework_Test $test, Exception $e)
*/
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e)
{
- $this->write('F');
- $this->nextColumn();
-
+ $this->writeProgress('F');
$this->lastTestFailed = TRUE;
}
@@ -410,9 +423,7 @@ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_Asser
*/
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e)
{
- $this->write('I');
- $this->nextColumn();
-
+ $this->writeProgress('I');
$this->lastTestFailed = TRUE;
}
@@ -426,9 +437,7 @@ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e)
*/
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e)
{
- $this->write('S');
- $this->nextColumn();
-
+ $this->writeProgress('S');
$this->lastTestFailed = TRUE;
}
@@ -441,6 +450,26 @@ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e)
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{
+ if ($this->verbose) {
+ $name = $suite->getName();
+
+ if (empty($name)) {
+ $name = 'Test Suite';
+ }
+
+ $this->write(
+ sprintf(
+ "%s%s%s\n",
+
+ $this->lastEvent == self::EVENT_TESTSUITE_END ? "\n" : '',
+ str_repeat(' ', $this->depth),
+ $name
+ )
+ );
+
+ $this->depth++;
+ $this->lastEvent = self::EVENT_TESTSUITE_START;
+ }
}
/**
@@ -452,6 +481,17 @@ public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
+ if ($this->verbose) {
+ $this->depth--;
+ }
+
+ $this->column = 0;
+
+ if ($this->lastEvent != self::EVENT_TESTSUITE_END) {
+ $this->write("\n");
+ }
+
+ $this->lastEvent = self::EVENT_TESTSUITE_END;
}
/**
@@ -462,6 +502,7 @@ public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
*/
public function startTest(PHPUnit_Framework_Test $test)
{
+ $this->lastEvent = self::EVENT_TEST_START;
}
/**
@@ -473,19 +514,26 @@ public function startTest(PHPUnit_Framework_Test $test)
public function endTest(PHPUnit_Framework_Test $test)
{
if (!$this->lastTestFailed) {
- $this->write('.');
- $this->nextColumn();
+ $this->writeProgress('.');
}
+ $this->lastEvent = self::EVENT_TEST_END;
$this->lastTestFailed = FALSE;
}
/**
+ * @param string $progress
* @access protected
*/
- protected function nextColumn()
+ protected function writeProgress($progress)
{
- if ($this->column++ >= 40) {
+ if ($this->column == 0) {
+ $this->write(str_repeat(' ', $this->depth - 1));
+ }
+
+ $this->write($progress);
+
+ if ($this->column++ >= 40 - $this->depth) {
$this->column = 0;
$this->write("\n");
}

0 comments on commit 7f40d8f

Please sign in to comment.