ez-php / testing-application
Framework-coupled test base classes for ez-php — ApplicationTestCase, DatabaseTestCase, HttpTestCase
Requires
- php: ^8.5
- ez-php/contracts: 0.*
- ez-php/framework: 0.*
- ez-php/http: 0.*
- ez-php/testing: 0.*
- phpunit/phpunit: ^13.0
Requires (Dev)
- ez-php/docker: 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-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]); } }
Requirements
- PHP 8.5+
- ez-php/framework
- ez-php/testing (for
TestResponse)