Skip to content

Captor

Rasuvaeff\Understudy\Captor

ClassPackage: rasuvaeff/understudySourceVersion: v0.4.1

Type parameters:

  • T of mixed = mixed

A typed argument captor, built by Arg::captor().

php
$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

php
__construct(
    class-string|null $class = NULL,
)
ParameterTypeDefaultDescription
$classclass-string|nullNULLwhat capture() requires of the argument; null accepts anything

Methods

capture()

php
capture(): mixed

The 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()

php
last(): mixed

The most recently captured value.

Throws:

all()

php
all(): array

Every captured value, in call order.

record()

php
record(mixed $value): void

discard()

php
discard(): void