ez-php / testing
Test utilities for the ez-php framework — ApplicationTestCase, DatabaseTestCase, HttpTestCase, ModelFactory
1.5.1
2026-04-17 22:32 UTC
Requires
- php: ^8.5
- ez-php/http: ^1.0
- ez-php/orm: ^1.0
- phpunit/phpunit: ^13.0
Requires (Dev)
- ez-php/docker: ^1.0
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
README
Framework-independent test utilities for ez-php — response assertions and an entity factory.
Looking for
ApplicationTestCase,DatabaseTestCase, orHttpTestCase? Those live inez-php/testing-application, which boots the full framework stack.
Requirements
- PHP 8.5+
- PHPUnit 13+
- ez-php/http
- ez-php/orm
Installation
composer require --dev ez-php/testing
Classes
TestResponse
Wraps a Response with a fluent PHPUnit assertion API. Returned by HttpTestCase helpers in ez-php/testing-application.
| Method | Description |
|---|---|
assertStatus(int) |
Exact status code |
assertOk() |
Status 200 |
assertNotFound() |
Status 404 |
assertRedirect(?string) |
3xx; optional Location header |
assertSee(string) |
Body contains substring |
assertJson(array) |
Body decodes to exact array |
assertHeader(string, ?string) |
Header present; optional value |
EntityFactory
Builds and optionally persists Entity instances with default attributes. Callable defaults are invoked once per instance. Persistence is delegated to an AbstractRepository.
use EzPhp\Testing\EntityFactory; $factory = new EntityFactory(User::class, $userRepo, [ 'name' => 'Alice', 'email' => fn () => uniqid('user_') . '@example.com', ]); $user = $factory->make(); // not persisted $user = $factory->create(); // persisted via $userRepo->save() $users = $factory->makeMany(3); $users = $factory->createMany(5, ['role' => 'admin']);
Setup (standalone development)
cp .env.example .env ./start.sh