WhenBuilder
Rasuvaeff\Understudy\WhenBuilder
Class — Package: rasuvaeff/understudy — Source — Version: v0.4.1
Type parameters:
TReturn of mixed = mixed
Configures what a stubbed call does.
TReturn is the return type of the specified method. Plain Psalm and PHPStan cannot infer it from the closure on their own — understudy-psalm fills it in, and until then the parameter stays mixed, which is why the template is declared here rather than added later: a published signature cannot grow one without changing its contract.
Constructor
__construct(
Expectation\Expectation $expectation,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$expectation | Expectation\Expectation | required |
Methods
returns()
returns(\TReturn $values): staticReturns each value in turn across successive calls, then keeps returning the last one.
throws()
throws(Throwable $error): staticanswers()
answers(callable $answer): staticthen()
then(): staticOpens the next link of the chain, so the verb that follows describes what the next call does:
when(fn () => $breaker->call($operation))
->returns('ok')
->then()->throws(new ConnectionLost());Once the chain runs out, its last link keeps answering.
times()
times(int<0, max> $minimum, int<0, max>|null $maximum = NULL): staticMakes the call count part of what verifyAll() checks. Without it a stub is permission, not a claim.
With one argument the count is exact; with two it is a range, and a null maximum means no upper bound.