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:
@ -12,6 +12,22 @@ use Pest\Exceptions\ShouldNotHappen;
|
||||
*/
|
||||
final class ChainableClosure
|
||||
{
|
||||
/**
|
||||
* Calls the given `$closure` when the given condition is true.
|
||||
*/
|
||||
public static function when(Closure $condition, Closure $next): Closure
|
||||
{
|
||||
return function () use ($condition, $next): void {
|
||||
if (! is_object($this)) { // @phpstan-ignore-line
|
||||
throw ShouldNotHappen::fromMessage('$this not bound to chainable closure.');
|
||||
}
|
||||
|
||||
if (\Pest\Support\Closure::bind($condition, $this, self::class)(...func_get_args())) {
|
||||
\Pest\Support\Closure::bind($next, $this, self::class)(...func_get_args());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls the given `$closure` and chains the `$next` closure.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user