Skip to content

Testing

Anvil\Test\InteractsWithAnvil sends actions through the real dispatcher, as the browser would:

Method Purpose
grantPermissions(array $permissions) the current user has exactly these permissions
dispatchComponent($panel, $component, $action, $input = [], $record = null, $context = []) issues a token for <panel>:<component> (current tenant, optional record UUID and context) and dispatches the action; returns the ComponentResponse
assertRejected(int $status, callable $callback) asserts an EndpointException with this status and returns it (errors, reason)
  • $component is given without the panel: triage:tickets for a page component, projects:checklist for a detail component. For components registered with register(), the id must start with <panel>: to be reachable this way.
  • The response exposes html, status, events, redirect and download.
  • Token check, permissions, validation, transaction and audit run as in production. Actions with Gate::AUTHENTICATED also need a logged in user (actingAs($user)).

Set-up of the test database, tenants and users: Testing.