ez-php/testing-application

Framework-coupled test base classes for ez-php — ApplicationTestCase, DatabaseTestCase, HttpTestCase

Maintainers

Package info

github.com/ez-php/testing-application

pkg:composer/ez-php/testing-application

Statistics

Installs: 1 554

Dependents: 21

Suggesters: 0

Stars: 0

Open Issues: 0

1.5.1 2026-04-17 22:32 UTC

This package is auto-updated.

Last update: 2026-04-17 22:36:02 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

MigrationBootstrap runs a set of migrations against a database before a test suite and tears them down after. Useful when DatabaseTestCase's transaction rollback is not enough (e.g. DDL tests or modules that need a schema but not a full application):

use EzPhp\Testing\MigrationBootstrap;

// In setUpBeforeClass() / tearDownAfterClass():
MigrationBootstrap::up($pdo, [
    __DIR__ . '/migrations/001_create_users.php',
    __DIR__ . '/migrations/002_create_posts.php',
]);

MigrationBootstrap::down($pdo, [
    __DIR__ . '/migrations/002_create_posts.php',
    __DIR__ . '/migrations/001_create_users.php',
]);

Requirements

  • PHP 8.5+
  • ez-php/framework
  • ez-php/testing (for TestResponse)