feat: add shared/global before each hook

This commit is contained in:
jordanbrauer
2021-03-28 02:03:31 -05:00
parent 7eb5478c42
commit 99500d0cae
3 changed files with 49 additions and 10 deletions

View File

@ -55,6 +55,15 @@ trait TestCase
$this->setGroups($groups);
}
/**
* Add a shared/"global" before each test hook that will execute **before**
* the test defined `beforeEach` hook.
*/
public function addBeforeEach(?Closure $hook): void
{
$this->beforeEach = $hook;
}
/**
* Add dependencies to the test case and map them to instances of ExecutionOrderDependency.
*/
@ -121,6 +130,10 @@ trait TestCase
parent::setUp();
if ($this->beforeEach instanceof Closure) {
$this->__callClosure($this->beforeEach, func_get_args());
}
$beforeEach = TestSuite::getInstance()->beforeEach->get(self::$__filename);
$this->__callClosure($beforeEach, func_get_args());