mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 09:47:23 +01:00
feat: add shared/global before each hook
This commit is contained in:
@ -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());
|
||||
|
||||
Reference in New Issue
Block a user