Skip to content

Commit

Permalink
Fixes sebastianbergmann#3031 based on 7.0.2 - getStatus() now detects…
Browse files Browse the repository at this point in the history
… thrown Exception inside tearDown()
  • Loading branch information
rafaelbeckel committed Mar 2, 2018
1 parent e2f8aa2 commit 41d1720
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 @@ -748,7 +748,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 @@ -178,6 +178,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 41d1720

Please sign in to comment.