From 41432ce31d87a21bff6990d102b9f540ea572da4 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Wed, 3 Jun 2015 06:59:57 +0200 Subject: [PATCH] Better fix for #1737 --- src/Util/TestDox/ResultPrinter.php | 133 +++++++++++++----------- src/Util/TestDox/ResultPrinter/Text.php | 19 ---- 2 files changed, 72 insertions(+), 80 deletions(-) diff --git a/src/Util/TestDox/ResultPrinter.php b/src/Util/TestDox/ResultPrinter.php index 8963be60cff..3b594d6e0ce 100644 --- a/src/Util/TestDox/ResultPrinter.php +++ b/src/Util/TestDox/ResultPrinter.php @@ -66,11 +66,6 @@ abstract class PHPUnit_Util_TestDox_ResultPrinter extends PHPUnit_Util_Printer i */ protected $incomplete = 0; - /** - * @var string - */ - protected $testTypeOfInterest = 'PHPUnit_Framework_TestCase'; - /** * @var string */ @@ -115,10 +110,12 @@ public function flush() */ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) { - if ($test instanceof $this->testTypeOfInterest) { - $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; - $this->failed++; + if (!$this->isOfInterest($test)) { + return; } + + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; + $this->failed++; } /** @@ -130,10 +127,12 @@ public function addError(PHPUnit_Framework_Test $test, Exception $e, $time) */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { - if ($test instanceof $this->testTypeOfInterest) { - $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; - $this->failed++; + if (!$this->isOfInterest($test)) { + return; } + + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; + $this->failed++; } /** @@ -145,10 +144,12 @@ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_Asser */ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time) { - if ($test instanceof $this->testTypeOfInterest) { - $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; - $this->incomplete++; + if (!$this->isOfInterest($test)) { + return; } + + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; + $this->incomplete++; } /** @@ -161,10 +162,12 @@ public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $t */ public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) { - if ($test instanceof $this->testTypeOfInterest) { - $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_RISKY; - $this->risky++; + if (!$this->isOfInterest($test)) { + return; } + + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_RISKY; + $this->risky++; } /** @@ -177,10 +180,12 @@ public function addRiskyTest(PHPUnit_Framework_Test $test, Exception $e, $time) */ public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time) { - if ($test instanceof $this->testTypeOfInterest) { - $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; - $this->skipped++; + if (!$this->isOfInterest($test)) { + return; } + + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; + $this->skipped++; } /** @@ -210,39 +215,38 @@ public function endTestSuite(PHPUnit_Framework_TestSuite $suite) */ public function startTest(PHPUnit_Framework_Test $test) { - if ($test instanceof $this->testTypeOfInterest) { - $class = get_class($test); - - if ($this->testClass != $class) { - if ($this->testClass != '') { - $this->doEndClass(); - } + if (!$this->isOfInterest($test)) { + return; + } - $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class); - $this->startClass($class); + $class = get_class($test); - $this->testClass = $class; - $this->tests = array(); + if ($this->testClass != $class) { + if ($this->testClass != '') { + $this->doEndClass(); } - $prettified = false; + $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class); + $this->startClass($class); - if ($test instanceof PHPUnit_Framework_TestCase && - !$test instanceof PHPUnit_Framework_Warning) { - $annotations = $test->getAnnotations(); + $this->testClass = $class; + $this->tests = array(); + } - if (isset($annotations['method']['testdox'][0])) { - $this->currentTestMethodPrettified = $annotations['method']['testdox'][0]; - $prettified = true; - } - } + $prettified = false; - if (!$prettified) { - $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(false)); - } + $annotations = $test->getAnnotations(); + + if (isset($annotations['method']['testdox'][0])) { + $this->currentTestMethodPrettified = $annotations['method']['testdox'][0]; + $prettified = true; + } - $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; + if (!$prettified) { + $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(false)); } + + $this->testStatus = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; } /** @@ -253,26 +257,28 @@ public function startTest(PHPUnit_Framework_Test $test) */ public function endTest(PHPUnit_Framework_Test $test, $time) { - if ($test instanceof $this->testTypeOfInterest) { - if (!isset($this->tests[$this->currentTestMethodPrettified])) { - if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { - $this->tests[$this->currentTestMethodPrettified]['success'] = 1; - $this->tests[$this->currentTestMethodPrettified]['failure'] = 0; - } else { - $this->tests[$this->currentTestMethodPrettified]['success'] = 0; - $this->tests[$this->currentTestMethodPrettified]['failure'] = 1; - } + if (!$this->isOfInterest($test)) { + return; + } + + if (!isset($this->tests[$this->currentTestMethodPrettified])) { + if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { + $this->tests[$this->currentTestMethodPrettified]['success'] = 1; + $this->tests[$this->currentTestMethodPrettified]['failure'] = 0; } else { - if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { - $this->tests[$this->currentTestMethodPrettified]['success']++; - } else { - $this->tests[$this->currentTestMethodPrettified]['failure']++; - } + $this->tests[$this->currentTestMethodPrettified]['success'] = 0; + $this->tests[$this->currentTestMethodPrettified]['failure'] = 1; + } + } else { + if ($this->testStatus == PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) { + $this->tests[$this->currentTestMethodPrettified]['success']++; + } else { + $this->tests[$this->currentTestMethodPrettified]['failure']++; } - - $this->currentTestClassPrettified = null; - $this->currentTestMethodPrettified = null; } + + $this->currentTestClassPrettified = null; + $this->currentTestMethodPrettified = null; } /** @@ -330,4 +336,9 @@ protected function endClass($name) protected function endRun() { } + + private function isOfInterest(PHPUnit_Framework_Test $test) + { + return $test instanceof PHPUnit_Framework_TestCase && get_class($test) != 'PHPUnit_Framework_Warning'; + } } diff --git a/src/Util/TestDox/ResultPrinter/Text.php b/src/Util/TestDox/ResultPrinter/Text.php index 7830fc6479c..29c925b3b43 100644 --- a/src/Util/TestDox/ResultPrinter/Text.php +++ b/src/Util/TestDox/ResultPrinter/Text.php @@ -21,11 +21,6 @@ */ class PHPUnit_Util_TestDox_ResultPrinter_Text extends PHPUnit_Util_TestDox_ResultPrinter { - /** - * @var bool - */ - private $isWarning = false; - /** * Handler for 'start class' event. * @@ -33,11 +28,6 @@ class PHPUnit_Util_TestDox_ResultPrinter_Text extends PHPUnit_Util_TestDox_Resul */ protected function startClass($name) { - if ($name == 'PHPUnit_Framework_Warning') { - $this->isWarning = true; - return; - } - $this->write($this->currentTestClassPrettified . "\n"); } @@ -49,10 +39,6 @@ protected function startClass($name) */ protected function onTest($name, $success = true) { - if ($this->isWarning) { - return; - } - if ($success) { $this->write(' [x] '); } else { @@ -69,11 +55,6 @@ protected function onTest($name, $success = true) */ protected function endClass($name) { - if ($this->isWarning) { - $this->isWarning = false; - return; - } - $this->write("\n"); } }