Skip to content

Commit

Permalink
Add better setUp and tearDown flow for TestCases
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasGuilloux committed Jan 29, 2021
1 parent 19e8995 commit d22d3d6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions TestTrait/BeforeAndAfterTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,17 @@
*/
trait BeforeAndAfterTestTrait
{
/** @var bool */
protected static $holdBeforeTest = false;

/** @var bool */
protected static $holdAfterTest = false;

public function setUp(): void
{
parent::setUp();

if (!static::$holdBeforeTest) {
$this->beforeTest();
}
$this->setUpTestCase();
$this->beforeTest();
}

protected function setUpTestCase(): void
{
// Override this to execute code before each test (reserved to TestCase)
}

protected function beforeTest(): void
Expand All @@ -33,13 +31,17 @@ protected function beforeTest(): void

public function tearDown(): void
{
if (!static::$holdAfterTest) {
$this->afterTest();
}
$this->afterTest();
$this->tearDownTestCase();

parent::tearDown();
}

protected function tearDownTestCase(): void
{
// Override this to execute code after each test (reserved to TestCase)
}

protected function afterTest(): void
{
// Override this to execute code after each test
Expand Down

0 comments on commit d22d3d6

Please sign in to comment.