Repository navigation
API Testing
Caligrafy Quill 2.26.0. Generated from the source by
php qa/build-api-reference.php; the guides explain how to use these classes, this reference says exactly what each public method takes and returns. Back to the API reference.
The base class of the tests of an application (tests/, php caligrafer.php test).
| Class | What it is |
|---|---|
Caligrafy\Testing\TestCase |
Test what the app does through its capabilities, as the pages, REST, the JS client and agents reach them |
namespace Caligrafy\Testing;
abstract class TestCase extends \PHPUnit\Framework\TestCaseSource: framework/testing/TestCase.php:41
Test what the app does through its capabilities, as the pages, REST, the JS client and agents reach them:
final class BooksTest extends Caligrafy\Testing\TestCase
{
public function testAReaderAddsABook(): void
{
$book = $this->call('create_book', ['title' => 'Dune'], $this->user(1));
$this->assertSame('Dune', $book['title']);
$this->assertCapabilityFails('invalid', 'create_book', [], $this->user(1));
$this->assertCapabilityFails('unauthenticated', 'create_book', ['title' => 'Dune'], 'guest');
$this->assertStringContainsString('Dune', $this->render('Books/list', ['books' => [$book]]));
}
}
Each test runs in a database transaction that is rolled back at its end (with DB_ACTIVATE=true), so tests leave the database as they found it; a CREATE, ALTER or DROP ends the transaction (MySQL commits it). Use a database of its own for tests: DB_TEST_DATABASE in .env, or the settings of .env.testing. Bindings of the container, the cache's copies and the query shapes the N+1 warning counts (Query::forgetShapes) are forgotten between tests.
->setUp()->tearDown()->call()->action()->assertCapabilityFails()->user()->render()->fake()->assertQueued()
protected function setUp(): voidNo doc comment.
Returns void
Source: framework/testing/TestCase.php:48
protected function tearDown(): voidNo doc comment.
Returns void
Source: framework/testing/TestCase.php:65
protected function call($capability, array $input = array(), $as = null)Calls a capability as a channel would, with its permission checks, validation and audit
Parameters
$capability-
$inputarray, defaultarray() -
$asContext|object|array|string|null, defaultnull: null: the command line (full access); 'guest'; a user (see user()); or a Context
Returns mixed: its answer
Source: framework/testing/TestCase.php:84
protected function action($capability, array $input = array(), $as = null)Calls a webOnly capability as Route::action() does (2.21.0)
Parameters
$capability-
$inputarray, defaultarray() -
$as, defaultnull
Returns mixed: its answer: a Caligrafy\Web (describe() says what it answers), or plain data
Source: framework/testing/TestCase.php:93
protected function assertCapabilityFails($kind, $capability, array $input = array(), $as = null)Asserts that a capability refuses: invalid, unauthenticated, forbidden, not_found or conflict
Parameters
$kind$capability-
$inputarray, defaultarray() -
$as, defaultnull
Returns ServiceError: the error, to check its message or fields
Source: framework/testing/TestCase.php:104
protected function user($id = 1, $level = 0, array $attributes = array())A signed-in user for call(): an id and a permission level (the users column Context::$levelAttribute), plus any other attributes the capability reads
Parameters
-
$id, default1 -
$level, default0 -
$attributesarray, defaultarray()
Source: framework/testing/TestCase.php:119
protected function render($view, array $data = array())The HTML of a Pug view of application/views, as a page would show it
Parameters
$view-
$dataarray, defaultarray()
Source: framework/testing/TestCase.php:127
protected function fake($id, $object)Replaces what the container gives for $id (a mailer, a payment gateway) with $object, for this test
Parameters
$id$object
Source: framework/testing/TestCase.php:141
protected function assertQueued($capability, ?callable $where = null)Asserts that a job of this capability was pushed to the queue (in this test), and returns its input
Parameters
$capability-
$where?callable, defaultnull
Caligrafy: Describe it. Approve it. Ship it. Your idea turned into a complete app: every feature built once, for web pages, Vue apps, a REST API and AI agents, and online.
Why Caligrafy: the benefits, the measurements, and what it is not yet
-
Quickstart with Claude: describe it, approve it, ship it
or the Quickstart: the same three steps by hand, in 5 minutes
- How Caligrafy works: the ideas in 5 minutes
- Your first capability: build a feature, page included
-
Capabilities in depth
-
#[Capability]: every option - Scheduled jobs: capabilities on a timer
- Notifications: web push and email
- Background jobs: capabilities run later
- Migrations: database changes, in order
- The cache
-
Testing your app
- Dependency injection
- Validation rules
-
Web pages
- Views and page components
- Design styles: another look, one setting
- Declarative routes: every request, in one line
-
Route::page·Route::form·Route::auth·Route::webhook·Route::download·Route::redirect·Route::action·Route::snap· capability routes - How to export a list as CSV
- Controllers: moving one to a declared route · how to, step by step
- Forms and helpers
-
Vue apps
-
Mobile and tablet
-
REST API
-
AI agents
-
Snap Cards and the assistant
- Payments: Stripe and crypto
- Face detection and face login
- OpenAI: chat and images · Assistants
- Open models: Llama, Mistral...
- Chatbots with Watson
- Machine learning in the browser
- Metadata and social cards · search and analytics
-
Putting it online: the production image, the database at every start
-
API reference: every class and method
-
Routing ·
Route·AuthRoutes· pages ·Controller· capabilities -
Data ·
Model·Query· sign-in · jobs ·Notify· payments · AI -
Interfaces · Snap ·
Snap\Cards·Snap\Conversation· testing · tooling · helper functions
-
Routing ·
-
Caligrafer: every command
- Project · build · data · agents · jobs and tests · maintenance · deploy
- Installation, configuration and Caligrafer
- Routing · Request · Controllers · Views
- Vue: flow of information · routes · validations
- Security and upgrading
- Release notes: 2.26 · 2.25 · 2.24 · 2.23 · 2.22 · 2.21 · 2.20 · 2.19 · 2.18 · 2.17 · 2.16 · 2.15 · 2.14 · 2.13 · 2.12 · 2.11 · 2.10 · 2.9 · 2.8 · 2.7 · 2.6 · 2.5 · 2.4 · 2.3 · 2.1 · October 2026 · changelog
- Testing Caligrafy (contributors)