ez-php / testing-application
Framework-coupled test base classes for ez-php — ApplicationTestCase, DatabaseTestCase, HttpTestCase
Requires
- php: ^8.5
- ez-php/console: ^2.0
- ez-php/contracts: ^2.0
- ez-php/framework: ^2.0
- ez-php/http: ^2.0
- ez-php/testing: ^2.0
- phpunit/phpunit: ^13.0
Requires (Dev)
- ez-php/docker: ^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
None
Provides
None
Conflicts
None
Replaces
None
- dev-main
- 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.4
- 0.8.3
- 0.8.2
This package is auto-updated.
Last update: 2026-09-16 14:35:16 UTC
README
Framework-coupled PHPUnit base classes for ez-php applications.
This package provides ApplicationTestCase, DatabaseTestCase, and HttpTestCase — test base classes that boot the full ez-php Application stack. It is the framework-aware companion to ez-php/testing, which contains the framework-independent utilities (TestResponse, ModelFactory).
Installation
composer require --dev ez-php/testing-application
Base Classes
ApplicationTestCase
Bootstraps a fresh Application instance before each test.
use EzPhp\Testing\ApplicationTestCase; final class MyTest extends ApplicationTestCase { protected function configureApplication(Application $app): void { $app->register(MyServiceProvider::class); } public function testSomething(): void { $service = $this->app()->make(MyService::class); // ... } }
DatabaseTestCase
Extends ApplicationTestCase. Wraps each test in a database transaction that is rolled back on teardown — no table truncation needed.
use EzPhp\Testing\DatabaseTestCase; final class UserRepositoryTest extends DatabaseTestCase { protected function getBasePath(): string { // Return path to an app root with config/db.php } public function testInsert(): void { $this->pdo()->exec("INSERT INTO users (name) VALUES ('Alice')"); // rolled back automatically after the test } }
HttpTestCase
Extends ApplicationTestCase. Dispatches fake HTTP requests through the full middleware and routing stack — no HTTP server required.
use EzPhp\Testing\HttpTestCase; final class ApiTest extends HttpTestCase { protected function configureApplication(Application $app): void { $app->register(ApiRouteProvider::class); } public function testGetUser(): void { $this->get('/users/1')->assertOk()->assertJson(['id' => 1]); } }
MigrationBootstrap / SeederBootstrap
Both are one-shot utilities for a test-suite bootstrap script (e.g. phpunit.xml's
<bootstrap>), not per-test base classes — they boot a fresh Application against the
test database and run the equivalent console command (ez migrate / ez db:seed) once,
before any test runs:
// bootstrap/test-setup.php require __DIR__ . '/../vendor/autoload.php'; use EzPhp\Testing\MigrationBootstrap; use EzPhp\Testing\SeederBootstrap; MigrationBootstrap::run(__DIR__ . '/..'); SeederBootstrap::run(__DIR__ . '/..');
<!-- phpunit.xml --> <phpunit bootstrap="bootstrap/test-setup.php">
Both swap DB_DATABASE for DB_TESTING_DATABASE first (when the latter is set), so
migrations/seeders run against the test schema, not production. A non-zero exit code from
the underlying command is thrown as a RuntimeException, failing the suite immediately
with a clear message rather than letting every test fail against an unmigrated/unseeded
database.
Requirements
- PHP 8.5+
- ez-php/framework
- ez-php/testing (for
TestResponse)