Skip to content

Commit

Permalink
Better fix for #1737
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Jun 3, 2015
1 parent 00b9b5d commit 41432ce
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 80 deletions.
133 changes: 72 additions & 61 deletions src/Util/TestDox/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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++;
}

/**
Expand All @@ -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++;
}

/**
Expand All @@ -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++;
}

/**
Expand All @@ -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++;
}

/**
Expand All @@ -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++;
}

/**
Expand Down Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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';
}
}
19 changes: 0 additions & 19 deletions src/Util/TestDox/ResultPrinter/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,13 @@
*/
class PHPUnit_Util_TestDox_ResultPrinter_Text extends PHPUnit_Util_TestDox_ResultPrinter
{
/**
* @var bool
*/
private $isWarning = false;

/**
* Handler for 'start class' event.
*
* @param string $name
*/
protected function startClass($name)
{
if ($name == 'PHPUnit_Framework_Warning') {
$this->isWarning = true;
return;
}

$this->write($this->currentTestClassPrettified . "\n");
}

Expand All @@ -49,10 +39,6 @@ protected function startClass($name)
*/
protected function onTest($name, $success = true)
{
if ($this->isWarning) {
return;
}

if ($success) {
$this->write(' [x] ');
} else {
Expand All @@ -69,11 +55,6 @@ protected function onTest($name, $success = true)
*/
protected function endClass($name)
{
if ($this->isWarning) {
$this->isWarning = false;
return;
}

$this->write("\n");
}
}

0 comments on commit 41432ce

Please sign in to comment.