ez-php / testing
Test utilities for the ez-php framework — ApplicationTestCase, DatabaseTestCase, HttpTestCase, ModelFactory
Requires
- php: ^8.5
- ez-php/contracts: ^2.0
- ez-php/http: ^2.0
- ez-php/orm: ^2.0
- phpunit/phpunit: ^13.0
Requires (Dev)
- ez-php/docker: ^2.0
- ez-php/events: ^2.0
- ez-php/mail: ^2.0
- ez-php/notification: ^2.0
- ez-php/storage: ^2.0
- friendsofphp/php-cs-fixer: ^3.94
- phpstan/phpstan: ^2.1
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-strict-rules: ^2.0
Suggests
- ez-php/events: Needed for Fake\EventSpy
- ez-php/mail: Needed for Fake\FakeMailer
- ez-php/notification: Needed for Fake\FakeChannel
- ez-php/storage: Needed for Fake\FakeStorage
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 2.5.6
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.11
- 2.4.10
- 2.4.9
- 2.4.8
- 2.4.7
- 2.4.6
- 2.4.5
- 2.4.4
- 2.4.3
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.9
- 2.3.8
- 2.3.7
- 2.3.6
- 2.3.5
- 2.3.4
- 2.3.3
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.1
- 2.2.0
- 2.1.1
- 2.1.0
- 2.0.1
- 2.0.0
- 1.14.0
- 1.13.1
- 1.13.0
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.2
- 1.11.1
- 1.11.0
- 1.10.0
- 1.9.2
- 1.9.1
- 1.9.0
- 1.8.0
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.2
- 1.4.1
- 1.4.0
- 1.3.0
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.1
- 1.0.0
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.6
- 0.8.5
- 0.8.4
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.1
- 0.5.0
- 0.4.1
- 0.4.0
This package is auto-updated.
Last update: 2026-09-30 19:50:26 UTC
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']);
Fakes
Recording doubles that let a test assert what the code under test did, without a driver, a mail server or a worker. The packages behind FakeMailer, FakeChannel, EventSpy and FakeStorage are optional (suggest) — install the one you use.
use EzPhp\Testing\Fake\{FakeQueue, FakeMailer, FakeChannel, EventSpy, FakeStorage}; $queue = new FakeQueue(); // QueueInterface (ez-php/contracts) (new Signup($queue))->register('a@b.c'); $queue->assertPushed(SendWelcomeMail::class, fn ($job) => $job->to === 'a@b.c'); $queue->assertPushedTimes(SendWelcomeMail::class, 1); $queue->assertNothingPushed(); // or assertNotPushed(Class::class) $mailer = new FakeMailer(); // MailerInterface (ez-php/mail) $mailer->assertSent(WelcomeMail::class, fn ($m) => $m->getToAddress() === 'a@b.c'); $mailer->assertSentCount(1); $mailer->assertNothingSent(); $channel = new FakeChannel(); // notification channel (ez-php/notification) $channel->assertSentTo($user, InvoicePaid::class); $spy = EventSpy::attachTo($dispatcher); // ez-php/events — real listeners still run $spy->assertDispatched(UserRegistered::class); // assertDispatchedTimes / assertNotDispatched / assertNothingDispatched $storage = new FakeStorage(); // StorageInterface over storage's InMemoryDriver $storage->assertExists('avatars/1.png'); // assertMissing / assertContents / assertEmpty
Each assert* takes an optional Closure to filter on the job/mail/event, and fails with a normal PHPUnit assertion message. EventDispatcher is final, so events are observed with a spy rather than replaced; use named event classes (anonymous ones are not matched by the dispatcher's wildcard listeners).
Setup (standalone development)
cp .env.example .env ./start.sh