Captor
Rasuvaeff\Understudy\Captor
Class — Package: rasuvaeff/understudy — Source — Version: v0.4.1
Type parameters:
T of mixed = mixed
A typed argument captor, built by Arg::captor().
$options = Arg::captor(DeliveryOptions::class);
when(fn () => $store->temporaryUrl(Arg::any(), Arg::any(), $options->capture()))
->returns('https://…');
$subject->run();
Assert::same($options->last()->downloadName, 'my report.pdf');capture() matches like Arg::instanceOf() for the typed form and like Arg::any() for the untyped one, and the argument is recorded only when the whole specification matched the call — a matcher can be asked about a call whose other arguments then reject it, and about no call at all while a failure message is rendered, and neither of those is a capture.
Values live until the context that captured them ends: reset() — the adapters call it after each test — and a closing Understudy::scope() drop them, the same way they drop the call log. The captor object itself is reusable after that; it is simply empty again.
Constructor
__construct(
class-string|null $class = NULL,
)| Parameter | Type | Default | Description |
|---|---|---|---|
$class | class-string|null | NULL | what capture() requires of the argument; null accepts anything |
Methods
capture()
capture(): mixedThe matcher to place where the argument to capture goes. Declared mixed for the same reason every Arg::* factory is: it stands in for a value of whatever type the parameter declares.
last()
last(): mixedThe most recently captured value.
Throws:
Exception\NothingCaptured— when no matched call carried one
all()
all(): arrayEvery captured value, in call order.
record()
record(mixed $value): voiddiscard()
discard(): void