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

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Pest\PendingObjects;
use Closure;
use Pest\Exceptions\InvalidUsesPath;
use Pest\TestSuite;
@ -12,6 +13,13 @@ use Pest\TestSuite;
*/
final class UsesCall
{
/**
* Contains a global before each hook closure to be executed.
*
* @var Closure
*/
private $beforeEach;
/**
* Holds the class and traits.
*
@ -97,11 +105,26 @@ final class UsesCall
return $this;
}
/**
* Sets the global beforeEach test hook
*/
public function beforeEach(Closure $hook): UsesCall
{
$this->beforeEach = $hook;
return $this;
}
/**
* Dispatch the creation of uses.
*/
public function __destruct()
{
TestSuite::getInstance()->tests->use($this->classAndTraits, $this->groups, $this->targets);
TestSuite::getInstance()->tests->use(
$this->classAndTraits,
$this->groups,
$this->targets,
$this->beforeEach,
);
}
}