Running a site
Testing
This page covers two kinds of tests. Your site's own tests use LapisTestCase, which boots the site on temporary storage. Lapis's own tests run inside the package, on a fixture site of their own.
Testing your site
A site built on Lapis can use Lapis\Testing\LapisTestCase for its tests. It boots the site on temporary storage, so a test never touches the real database:
use Lapis\Testing\LapisTestCase; final class BlogTest extends LapisTestCase { public function test_a_post_shows_its_body(): void { $this->page('blog/first', 'First', type: 'post')->withBlocks(['body' => ['type' => 'richtext', 'value' => '<p>Hello</p>']]); $this->assertRouteResolves('blog/first', 'blog/[slug].post.php'); $this->assertSeeText($this->visit('/blog/first')->assertOk(), 'Hello'); } public function test_drafts_are_private(): void { $this->page('about')->withBlocks(['title' => 'Live'])->withDrafts(['title' => 'Draft']); $this->assertDontSeeText($this->visit('/about'), 'Draft'); $this->actingAsEditor(); $this->assertSeeText($this->visit('/about'), 'Draft'); } }
Helpers: page(), globals(), settings(), upload(), image(), variantSize(), useImage(), imageTag(), table(), actingAsEditor(role: Role::Editor) (an admin by default), asGuest(), withEditMode(), visit(), htmx(), attemptLogin(), api(), renderBlock(), editorState(), fakeHttp() (import map downloads without network), fakeMail(), formToken(), $siteRoot (a site outside the working directory), $copySite = true (when the test writes the site's files). Assertions: assertBlock(), assertDraft(), assertPublished(), assertVariant(), assertPluginLoaded(), assertRouteResolves(), assertRouteMissing(), assertSeeEditor(), assertDontSeeEditor(), assertCached(), assertNotCached(), assertSeeText(), assertDontSeeText(), assertHeaderContains().
Testing Lapis itself
Every test of the package runs inside the package, on its own fixture site (tests/Fixtures/site). None depends on an outside site:
composer install composer test # Pest: unit and integration tests, on temporary storage npm install && npx playwright install chromium npm run e2e # Playwright: starts the fixture site with `php -S` on 127.0.0.1:8000 LAPIS_E2E_URL=https://lapis-fixture.test npm run e2e # against a server you run yourself
Override DB_HOST, DB_PORT, DB_USERNAME and DB_PASSWORD in the environment to point the configs at your database servers:
vendor/bin/pest -c phpunit.mysql.xml vendor/bin/pest -c phpunit.pgsql.xml
The fixture site has its own entry point (tests/Fixtures/site/public/index.php) and console (php tests/Fixtures/site/lapis). The E2E run starts with an empty database. Without a .env in the package, the tests write one with a throwaway key.
Lint and static analysis
Mago checks the package at its strictest, and so do the plugins: every linter rule that applies is on (documentation, complexity, no side effects in conditions included), the analyzer runs with its strictness switches on (types, nulls, exceptions, dead code), and every level fails, down to notes. Every rule is listed in mago.toml, so an update of Mago cannot change one unnoticed. Tempest's formatter settings format the code.
A site made from the starter (lapis/app) gets a mago.toml too, as Tempest uses Mago: its default rules without those Tempest turns off (complexity metrics, a few style rules). Pages and components are templates and stay out of it: rendering them checks them.
composer format # vendor/bin/mago fmt composer lint # vendor/bin/mago lint composer analyze # vendor/bin/mago analyze composer check # formatting, lint and analysis, then the tests
There is no baseline: every finding fails, and a finding is fixed, not set aside. Where a rule is wrong for a line or a class on purpose (a cohesive class over the complexity limits, a constructor of autowired services), a @mago-expect comment there says which rule and why. Exceptions that are bugs rather than cases for the caller (PHP's errors, SiteCodeWasInvalid for a broken site or plugin file, the container's) are unchecked-exceptions in mago.toml. Every other one is caught or named in a @throws. The analyzer leaves out tests/, because Pest binds $this in its test closures and Mago cannot follow that. The linter checks the tests too.
Tempest workarounds
Lapis works around some Tempest behaviors. The list, with the tests that cover them: Tempest workarounds.