Functions
The free functions understudy declares in src/functions.php, autoloaded through composer's files entry. They are the primary surface: every example in this guide opens with one. Each has a collision-free static twin on Understudy — see Using Pest for when that matters.
| Function | Returns | Summary |
|---|---|---|
expect() | ExpectBuilder | Declares a call the code under test is expected to make: exactly once unless times() says… |
expectSequence() | void | Arms a protocol before the code under test runs: a call that breaks the order fails at that call,… |
verify() | void | Asserts, after the fact, how many times a call was made. |
when() | WhenBuilder | Stubs a call: allowed any number of times, including none. |
expect()
Rasuvaeff\Understudy\expect() · Source
expect(callable $call): ExpectBuilderDeclares a call the code under test is expected to make: exactly once unless times() says otherwise, checked by Understudy::verifyAll().
expect(fn () => $repository->save($book));Pest declares a global expect() of its own. In a Pest suite either import this one under another name — use function Rasuvaeff\Understudy\expect as expectCall; — or call Understudy::expect(), which cannot collide.
| Parameter | Type | Description |
|---|---|---|
$call | callable |
expectSequence()
Rasuvaeff\Understudy\expectSequence() · Source
expectSequence(callable ...$calls): voidArms a protocol before the code under test runs: a call that breaks the order fails at that call, not in teardown.
expectSequence(
fn () => $repo->begin(),
fn () => $repo->save($book),
fn () => $repo->commit(),
);| Parameter | Type | Description |
|---|---|---|
...$calls | callable |
verify()
Rasuvaeff\Understudy\verify() · Source
verify(callable $call, int<0, max>|null $times = NULL, int<0, max>|null $minimum = NULL, int<0, max>|null $maximum = NULL, bool $never = false): voidAsserts, after the fact, how many times a call was made.
verify(fn () => $repository->recordView($book), times: 2);| Parameter | Type | Description |
|---|---|---|
$call | callable | |
$times = NULL | int<0, max>|null | |
$minimum = NULL | int<0, max>|null | |
$maximum = NULL | int<0, max>|null | |
$never = false | bool |
when()
Rasuvaeff\Understudy\when() · Source
when(callable $call): WhenBuilderStubs a call: allowed any number of times, including none.
when(fn () => $repository->find(123))->returns($book);| Parameter | Type | Description |
|---|---|---|
$call | callable |