Skip to content

Commit

Permalink
Call hook methods only if they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Naktibalda committed Feb 6, 2019
1 parent 4c4f2ca commit ac13711
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,32 @@

abstract class TestCase extends \PHPUnit\Framework\TestCase
{
protected abstract function _setUp();
protected abstract function _tearDown();
public static abstract function _setUpBeforeClass();
public static abstract function _tearDownAfterClass();

protected function setUp(): void
{
self::_setUp();
if (method_exists($this, '_setUp')) {
$this->_setUp();
}
}

protected function tearDown(): void
{
self::_tearDown();
if (method_exists($this, '_tearDown')) {
$this->_tearDown();
}
}

public static function setUpBeforeClass(): void
{
self::_setUpBeforeClass();
if (method_exists(get_called_class(), '_setUpBeforeClass')) {
static::_setUpBeforeClass();
}
}

public static function tearDownAfterClass(): void
{
self::_tearDownAfterClass();
if (method_exists(get_called_class(), '_tearDownAfterClass')) {
static::_tearDownAfterClass();
}
}
}
}

0 comments on commit ac13711

Please sign in to comment.