feat(describe): more refactors

This commit is contained in:
Nuno Maduro
2023-05-26 20:04:50 +01:00
parent 551fa01415
commit 0ae0887665
4 changed files with 10 additions and 10 deletions

View File

@ -98,7 +98,7 @@ trait Testable
}
self::$__beforeAll = (self::$__beforeAll instanceof Closure)
? ChainableClosure::fromStatic(self::$__beforeAll, $hook)
? ChainableClosure::boundStatically(self::$__beforeAll, $hook)
: $hook;
}
@ -112,7 +112,7 @@ trait Testable
}
self::$__afterAll = (self::$__afterAll instanceof Closure)
? ChainableClosure::fromStatic(self::$__afterAll, $hook)
? ChainableClosure::boundStatically(self::$__afterAll, $hook)
: $hook;
}
@ -156,7 +156,7 @@ trait Testable
$beforeAll = TestSuite::getInstance()->beforeAll->get(self::$__filename);
if (self::$__beforeAll instanceof Closure) {
$beforeAll = ChainableClosure::fromStatic(self::$__beforeAll, $beforeAll);
$beforeAll = ChainableClosure::boundStatically(self::$__beforeAll, $beforeAll);
}
call_user_func(Closure::bind($beforeAll, null, self::class));
@ -170,7 +170,7 @@ trait Testable
$afterAll = TestSuite::getInstance()->afterAll->get(self::$__filename);
if (self::$__afterAll instanceof Closure) {
$afterAll = ChainableClosure::fromStatic(self::$__afterAll, $afterAll);
$afterAll = ChainableClosure::boundStatically(self::$__afterAll, $afterAll);
}
call_user_func(Closure::bind($afterAll, null, self::class));

View File

@ -53,7 +53,7 @@ final class AfterEachCall
$proxies = $this->proxies;
$afterEachTestCase = ChainableClosure::when(
$afterEachTestCase = ChainableClosure::boundWhen(
fn (): bool => is_null($describing) || $this->__describing === $describing, // @phpstan-ignore-line
ChainableClosure::bound(fn () => $proxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line
)->bindTo($this, self::class);

View File

@ -68,7 +68,7 @@ final class BeforeEachCall
$this->testCallProxies->chain($testCall);
};
$beforeEachTestCase = ChainableClosure::when(
$beforeEachTestCase = ChainableClosure::boundWhen(
fn (): bool => is_null($describing) || $this->__describing === $describing, // @phpstan-ignore-line
ChainableClosure::bound(fn () => $testCaseProxies->chain($this), $this->closure)->bindTo($this, self::class), // @phpstan-ignore-line
)->bindTo($this, self::class);

View File

@ -13,9 +13,9 @@ use Pest\Exceptions\ShouldNotHappen;
final class ChainableClosure
{
/**
* Calls the given `$closure` when the given condition is true.
* Calls the given `$closure` when the given condition is true, "bound" to the same object.
*/
public static function when(Closure $condition, Closure $next): Closure
public static function boundWhen(Closure $condition, Closure $next): Closure
{
return function () use ($condition, $next): void {
if (! is_object($this)) { // @phpstan-ignore-line
@ -55,9 +55,9 @@ final class ChainableClosure
}
/**
* Call the given static `$closure` and chains the `$next` closure.
* Call the given static `$closure` and chains the `$next` closure, "bound" to the same object statically.
*/
public static function fromStatic(Closure $closure, Closure $next): Closure
public static function boundStatically(Closure $closure, Closure $next): Closure
{
return static function () use ($closure, $next): void {
\Pest\Support\Closure::bind($closure, null, self::class)(...func_get_args());