Adds support for scoped in HigherOrderExpectations.

This commit is contained in:
Luke Downing
2022-01-23 23:37:03 +00:00
parent d2ca6e630d
commit e91c85496f
2 changed files with 33 additions and 0 deletions

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Pest\Expectations;
use Closure;
use Pest\Concerns\Retrievable;
use Pest\Expectation;
@ -79,6 +80,21 @@ final class HigherOrderExpectation
return $this->expect($value);
}
/**
* Scope an expectation callback to the current value in
* the HigherOrderExpectation chain.
*
* @param Closure(Expectation<TValue>): void $expectation
*
* @return HigherOrderExpectation<TOriginalValue, TOriginalValue>
*/
public function scoped(Closure $expectation): self
{
$expectation->__invoke($this->expectation);
return new self($this->original, $this->original->value);
}
/**
* Dynamically calls methods on the class with the given arguments.
*