Merge pull request #668 from fabio-ivona/custom-expectations-fix

Store interceptors for use with Collision
This commit is contained in:
Nuno Maduro
2023-02-19 17:00:02 +00:00
committed by GitHub

View File

@ -19,6 +19,13 @@ trait Pipeable
*/
private static array $pipes = [];
/**
* The list of interceptors.
*
* @var array<string, array<Closure(Closure, mixed ...$arguments): void>>
*/
private static array $interceptors = [];
/**
* Register a pipe to be applied before an expectation is checked.
*/
@ -38,6 +45,8 @@ trait Pipeable
$filter = fn ($value): bool => $value instanceof $filter;
}
self::$interceptors[$name][] = $handler;
$this->pipe($name, function ($next, ...$arguments) use ($handler, $filter): void {
/* @phpstan-ignore-next-line */
if ($filter($this->value, ...$arguments)) {