Skip to content

Commit

Permalink
Fixes #3031 based on 7.0.2 - getStatus() now detects thrown Exception…
Browse files Browse the repository at this point in the history
… inside tearDown()
  • Loading branch information
rafaelbeckel authored and sebastianbergmann committed Apr 17, 2018
1 parent 9d8460c commit b881247
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,9 @@ public function runBare(): void
$this->status = BaseTestRunner::STATUS_FAILURE;
$this->statusMessage = $e->getMessage();
} catch (Throwable $_e) {
$e = $_e;
$e = $_e;
$this->status = BaseTestRunner::STATUS_ERROR;
$this->statusMessage = $_e->getMessage();
}

$this->mockObjects = [];
Expand Down
8 changes: 8 additions & 0 deletions tests/Framework/TestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@ public function testExceptionInTearDown(): void
$this->assertEquals(BaseTestRunner::STATUS_ERROR, $test->getStatus());
}

public function testExceptionInTestIsDetectedInTeardown(): void
{
$test = new \ExceptionInTestDetectedInTeardown('testSomething');
$test->run();

$this->assertTrue($test->exceptionDetected);
}

public function testNoArgTestCasePasses(): void
{
$result = new TestResult;
Expand Down
21 changes: 21 additions & 0 deletions tests/_files/ExceptionInTestDetectedInTeardown.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
use PHPUnit\Framework\TestCase;

use PHPUnit\Runner\BaseTestRunner;

class ExceptionInTestDetectedInTeardown extends TestCase
{
public $exceptionDetected = false;

public function testSomething()
{
throw new Exception;
}

protected function tearDown(): void
{
if (BaseTestRunner::STATUS_ERROR == $this->getStatus()) {
$this->exceptionDetected = true;
}
}
}

0 comments on commit b881247

Please sign in to comment.