preflow / testing
Preflow testing — test utilities for components, routes, data
v0.34.1
2026-10-23 21:46 UTC
Requires
- php: >=8.4
- nyholm/psr7: ^1.8
- phpunit/phpunit: ^11.0
- preflow/auth: ^0.1 || @dev
- preflow/components: ^0.1 || @dev
- preflow/core: ^0.1 || @dev
- preflow/data: ^0.25 || @dev
- preflow/htmx: ^0.1 || @dev
- preflow/i18n: ^0.1 || @dev
- preflow/routing: ^0.1 || @dev
- preflow/view: ^0.1 || @dev
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
- preflow/data: <0.25
Replaces
None
- dev-main
- v0.34.1
- v0.34.0
- v0.33.0
- v0.32.0
- v0.31.0
- v0.30.0
- v0.29.0
- v0.28.0
- v0.27.1
- v0.27.0
- v0.26.0
- v0.25.1
- v0.25.0
- v0.24.1
- v0.24.0
- v0.23.0
- v0.22.1
- v0.22.0
- v0.21.0
- v0.20.0
- v0.19.2
- v0.19.1
- v0.19.0
- v0.18.1
- v0.18.0
- v0.17.2
- v0.17.1
- v0.17.0
- v0.16.2
- v0.16.1
- v0.16.0
- v0.15.0
- v0.14.2
- v0.14.1
- v0.14.0
- v0.13.1
- v0.13.0
- v0.12.0
- v0.11.4
- v0.11.3
- v0.11.2
- v0.11.1
- v0.11.0
- v0.10.4
- v0.10.3
- v0.10.2
- v0.10.1
- v0.10.0
- v0.9.1
- v0.9.0
- v0.8.0
- v0.7.0
- v0.6.0
- v0.5.0
- v0.4.1
- v0.4.0
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.3
- v0.2.2
- v0.2.1
- v0.2.0
- v0.1.1
- v0.1.0
This package is auto-updated.
Last update: 2026-10-25 20:24:29 UTC
README
Test utilities for Preflow applications — components, routes, and data layers.
Installation
composer require preflow/testing --dev
What it does
- PHPUnit base cases for components, routes, and data
- Fluent HTTP response assertions wrapping PSR-7 responses
- In-memory SQLite and temporary JSON storage for isolated data tests
- Minimal
TestApplicationbootstrap (container, renderer, token service)
ComponentTestCase
Extend to test Preflow components. TestApplication is wired up automatically in setUp().
use Preflow\Testing\ComponentTestCase; final class ExampleCardTest extends ComponentTestCase { public function test_renders_title(): void { $html = $this->renderComponent(ExampleCard::class, [ 'title' => 'Hello', ]); $this->assertStringContainsString('Hello', $html); } public function test_initial_state(): void { $card = $this->createComponent(ExampleCard::class, ['title' => 'Hi']); $card->resolveState(); $this->assertSame('Hi', $card->title); } }
RouteTestCase + TestResponse
Wrap any PSR-7 ResponseInterface for fluent assertions.
use Preflow\Testing\RouteTestCase; final class HealthTest extends RouteTestCase { public function test_health_endpoint(): void { $psrResponse = $this->app->handle($request); // your PSR-7 response $this->createTestResponse($psrResponse) ->assertOk() ->assertJson() ->assertSee('"status":"ok"'); } }
TestResponse assertions
| Method | Description |
|---|---|
assertOk() |
Status 200 |
assertStatus(int $status) |
Exact status code |
assertSee(string $text) |
Body contains text |
assertNotSee(string $text) |
Body does not contain text |
assertRedirect(string $uri) |
3xx + matching Location header |
assertHeader(string $name, string $value) |
Exact header value |
assertHeaderContains(string $name, string $sub) |
Header contains substring |
assertJson() |
Content-Type contains "json" + valid JSON body |
assertForbidden() |
Status 403 |
assertNotFound() |
Status 404 |
assertUnauthorized() |
Status 401 |
All assertion methods return $this for chaining.
DataTestCase
Provides an in-memory SQLite connection and a temporary JSON directory, both torn down after each test.
use Preflow\Testing\DataTestCase; use Preflow\Data\Migration\Table; final class PostRepositoryTest extends DataTestCase { protected function setUp(): void { parent::setUp(); $this->createTable('posts', function (Table $table) { $table->uuid('uuid')->primary(); $table->string('title'); $table->timestamps(); }); } public function test_save_and_find(): void { $driver = $this->getSqliteDriver(); // use $driver or $this->dataManager() for ORM operations $pdo = $this->getPdo(); $pdo->exec("INSERT INTO posts (uuid, title) VALUES ('1', 'Hello')"); $row = $pdo->query("SELECT * FROM posts WHERE uuid = '1'")->fetch(); $this->assertSame('Hello', $row['title']); } }
DataTestCase methods
| Method | Returns |
|---|---|
getSqliteDriver() |
SqliteDriver (in-memory SQLite) |
getJsonDriver() |
JsonFileDriver (temp directory) |
dataManager() |
DataManager with both drivers registered |
createTable(string $name, callable $cb) |
Creates table via Schema builder |
getPdo() |
Raw \PDO instance |