mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 08:17:22 +01:00
feat(describe): improves logic around hooks
This commit is contained in:
@ -5,7 +5,8 @@ declare(strict_types=1);
|
||||
namespace Pest\Repositories;
|
||||
|
||||
use Closure;
|
||||
use Pest\Exceptions\BeforeEachAlreadyExist;
|
||||
use Pest\PendingCalls\BeforeEachCall;
|
||||
use Pest\Support\ChainableClosure;
|
||||
use Pest\Support\NullClosure;
|
||||
|
||||
/**
|
||||
@ -21,12 +22,18 @@ final class BeforeEachRepository
|
||||
/**
|
||||
* Sets a before each closure.
|
||||
*/
|
||||
public function set(string $filename, Closure $beforeEachTestCall, Closure $beforeEachTestCase): void
|
||||
public function set(string $filename, BeforeEachCall $beforeEachCall, Closure $beforeEachTestCall, Closure $beforeEachTestCase): void
|
||||
{
|
||||
if (array_key_exists($filename, $this->state)) {
|
||||
throw new BeforeEachAlreadyExist($filename);
|
||||
[$fromBeforeEachTestCall, $fromBeforeEachTestCase] = $this->state[$filename];
|
||||
|
||||
$beforeEachTestCall = ChainableClosure::from($fromBeforeEachTestCall, $beforeEachTestCall)->bindTo($beforeEachCall, $beforeEachCall::class);
|
||||
$beforeEachTestCase = ChainableClosure::from($fromBeforeEachTestCase, $beforeEachTestCase)->bindTo($beforeEachCall, $beforeEachCall::class);
|
||||
}
|
||||
|
||||
assert($beforeEachTestCall instanceof Closure);
|
||||
assert($beforeEachTestCase instanceof Closure);
|
||||
|
||||
$this->state[$filename] = [$beforeEachTestCall, $beforeEachTestCase];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user