Skip to content

Commit

Permalink
Fixes sebastianbergmann#3031 - getStatus() now detects thrown Excepti…
Browse files Browse the repository at this point in the history
…on inside tearDown()
  • Loading branch information
rafaelbeckel committed Mar 2, 2018
1 parent 3ff73dd commit 49b0b15
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,8 @@ public function runBare(): void
$this->statusMessage = $e->getMessage();
} catch (Throwable $_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->assertTrue($test->tearDown);
$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
{
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 49b0b15

Please sign in to comment.