mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 15:57:21 +01:00
feat(describe): improves logic around hooks
This commit is contained in:
@ -6,7 +6,7 @@ namespace Pest\Repositories;
|
||||
|
||||
use Closure;
|
||||
use Mockery;
|
||||
use Pest\Exceptions\AfterEachAlreadyExist;
|
||||
use Pest\PendingCalls\AfterEachCall;
|
||||
use Pest\Support\ChainableClosure;
|
||||
use Pest\Support\NullClosure;
|
||||
|
||||
@ -23,13 +23,18 @@ final class AfterEachRepository
|
||||
/**
|
||||
* Sets a after each closure.
|
||||
*/
|
||||
public function set(string $filename, Closure $closure): void
|
||||
public function set(string $filename, AfterEachCall $afterEachCall, Closure $afterEachTestCase): void
|
||||
{
|
||||
if (array_key_exists($filename, $this->state)) {
|
||||
throw new AfterEachAlreadyExist($filename);
|
||||
$fromAfterEachTestCase = $this->state[$filename];
|
||||
|
||||
$afterEachTestCase = ChainableClosure::from($fromAfterEachTestCase, $afterEachTestCase)
|
||||
->bindTo($afterEachCall, $afterEachCall::class);
|
||||
}
|
||||
|
||||
$this->state[$filename] = $closure;
|
||||
assert($afterEachTestCase instanceof Closure);
|
||||
|
||||
$this->state[$filename] = $afterEachTestCase;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -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