Alpha ZealPHP is early-stage and under active development. APIs may change between minor versions until v1.0. Feedback and bug reports welcome on GitHub.
API Index — Namespaces, Packages, Reports, Indices

Tester
in package

FinalYes

Drive a reactive component in a unit test, without a server or a browser:

Tester::render(Counter::class, ['count' => 1]) ->call('add', ['by' => 2]) ->assertSet('count', 3) ->assertSee('3');

Each step goes through the real component endpoint with the plain-HTTP protocol (Zeal-Request: 1), so snapshots, validation, authorize(), hooks, events and redirects behave exactly as in production. Assertions use PHPUnit when it's installed and throw \AssertionError otherwise.

Without ZEALPHP_APP_KEY the tester uses a random key for the process.

Table of Contents

Properties

$body  : string
$headers  : array<string, string>
$html  : string
$meta  : ComponentMeta
$status  : int

Methods

assertDispatched()  : self
assertDontSee()  : self
assertHasErrors()  : self
Every named field has an error; with none named, at least one error exists.
assertHasNoErrors()  : self
assertRedirect()  : self
assertSee()  : self
The markup contains $text (HTML-escaped first, unless $escape is false).
assertSet()  : self
assertStatus()  : self
call()  : self
Run an #[Action], like clicking its button.
errors()  : array<string, string>
events()  : array<string, mixed>
get()  : mixed
A public property's current value.
html()  : string
The component's current markup (its outer element included).
redirectedTo()  : string|null
Where the last step redirected the page, or null.
refresh()  : self
Re-render with the current state, like a push refresh.
render()  : self
Render a component (registering its class if needed).
set()  : self
Change a #[Model] property, like typing into its input: the field is validated and its updated{Prop}() hook runs. The other bound fields are sent with their current values, as a browser would.
status()  : int
HTTP status of the last step (200 before any).
__construct()  : mixed
check()  : self
currentFields()  : array<string, mixed>
The bound fields' current values, encoded as a form would send them.
field()  : array<string, mixed>
instance()  : Component
send()  : self
snapshot()  : Snapshot
wire()  : string

Properties

$headers

private array<string, string> $headers = []

$meta read-only

private ComponentMeta $meta

$status

private int $status = 200

Methods

assertDispatched()

public assertDispatched(string $event) : self
Parameters
$event : string
Return values
self

assertDontSee()

public assertDontSee(string $text[, bool $escape = true ]) : self
Parameters
$text : string
$escape : bool = true
Return values
self

assertHasErrors()

Every named field has an error; with none named, at least one error exists.

public assertHasErrors(string ...$fields) : self
Parameters
$fields : string
Return values
self

assertHasNoErrors()

public assertHasNoErrors() : self
Return values
self

assertRedirect()

public assertRedirect([string|null $to = null ]) : self
Parameters
$to : string|null = null
Return values
self

assertSee()

The markup contains $text (HTML-escaped first, unless $escape is false).

public assertSee(string $text[, bool $escape = true ]) : self
Parameters
$text : string
$escape : bool = true
Return values
self

assertSet()

public assertSet(string $prop, mixed $expected) : self
Parameters
$prop : string
$expected : mixed
Return values
self

assertStatus()

public assertStatus(int $status) : self
Parameters
$status : int
Return values
self

call()

Run an #[Action], like clicking its button.

public call(string $action[, array<string, mixed> $args = [] ]) : self
Parameters
$action : string
$args : array<string, mixed> = []
Return values
self

errors()

public errors() : array<string, string>
Return values
array<string, string> —

field → message

events()

public events() : array<string, mixed>
Return values
array<string, mixed> —

events the last step dispatched, name → detail

get()

A public property's current value.

public get(string $prop) : mixed
Parameters
$prop : string

html()

The component's current markup (its outer element included).

public html() : string
Return values
string

redirectedTo()

Where the last step redirected the page, or null.

public redirectedTo() : string|null
Return values
string|null

refresh()

Re-render with the current state, like a push refresh.

public refresh() : self
Return values
self

render()

Render a component (registering its class if needed).

public static render(Component>|string $component[, array<string, mixed> $props = [] ][, string|null $key = null ]) : self
Parameters
$component : Component>|string

a class or a registered name

$props : array<string, mixed> = []
$key : string|null = null
Return values
self

set()

Change a #[Model] property, like typing into its input: the field is validated and its updated{Prop}() hook runs. The other bound fields are sent with their current values, as a browser would.

public set(string $prop, mixed $value) : self
Parameters
$prop : string
$value : mixed
Return values
self

status()

HTTP status of the last step (200 before any).

public status() : int
Return values
int

__construct()

private __construct(ComponentMeta $meta) : mixed
Parameters
$meta : ComponentMeta

check()

private check(bool $ok, string $message) : self
Parameters
$ok : bool
$message : string
Return values
self

currentFields()

The bound fields' current values, encoded as a form would send them.

private currentFields() : array<string, mixed>
Return values
array<string, mixed>

field()

private static field(string $prop, mixed $value) : array<string, mixed>
Parameters
$prop : string
$value : mixed
Return values
array<string, mixed>

send()

private send(string $action, array<string, mixed> $fields) : self
Parameters
$action : string
$fields : array<string, mixed>
Return values
self

snapshot()

private snapshot() : Snapshot
Return values
Snapshot

wire()

private wire() : string
Return values
string
On this page