ez-php/testing-application 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ez-php/testing-application

Composer 安装命令:

composer require --dev ez-php/testing-application

包简介

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

README 文档

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)

统计信息

  • 总下载量: 2.76k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 21
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固