定制 preflow/testing 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

preflow/testing

Composer 安装命令:

composer require preflow/testing

包简介

Preflow testing — test utilities for components, routes, data

README 文档

README

Test utilities for Preflow applications — components, routes, and data layers.

Installation

composer require preflow/testing --dev

What it does

  • PHPUnit base cases for components, routes, and data
  • Fluent HTTP response assertions wrapping PSR-7 responses
  • In-memory SQLite and temporary JSON storage for isolated data tests
  • Minimal TestApplication bootstrap (container, renderer, token service)

ComponentTestCase

Extend to test Preflow components. TestApplication is wired up automatically in setUp().

use Preflow\Testing\ComponentTestCase;

final class ExampleCardTest extends ComponentTestCase
{
    public function test_renders_title(): void
    {
        $html = $this->renderComponent(ExampleCard::class, [
            'title' => 'Hello',
        ]);

        $this->assertStringContainsString('Hello', $html);
    }

    public function test_initial_state(): void
    {
        $card = $this->createComponent(ExampleCard::class, ['title' => 'Hi']);
        $card->resolveState();

        $this->assertSame('Hi', $card->title);
    }
}

RouteTestCase + TestResponse

Wrap any PSR-7 ResponseInterface for fluent assertions.

use Preflow\Testing\RouteTestCase;

final class HealthTest extends RouteTestCase
{
    public function test_health_endpoint(): void
    {
        $psrResponse = $this->app->handle($request); // your PSR-7 response

        $this->createTestResponse($psrResponse)
            ->assertOk()
            ->assertJson()
            ->assertSee('"status":"ok"');
    }
}

TestResponse assertions

Method Description
assertOk() Status 200
assertStatus(int $status) Exact status code
assertSee(string $text) Body contains text
assertNotSee(string $text) Body does not contain text
assertRedirect(string $uri) 3xx + matching Location header
assertHeader(string $name, string $value) Exact header value
assertHeaderContains(string $name, string $sub) Header contains substring
assertJson() Content-Type contains "json" + valid JSON body
assertForbidden() Status 403
assertNotFound() Status 404
assertUnauthorized() Status 401

All assertion methods return $this for chaining.

DataTestCase

Provides an in-memory SQLite connection and a temporary JSON directory, both torn down after each test.

use Preflow\Testing\DataTestCase;
use Preflow\Data\Migration\Table;

final class PostRepositoryTest extends DataTestCase
{
    protected function setUp(): void
    {
        parent::setUp();

        $this->createTable('posts', function (Table $table) {
            $table->uuid('uuid')->primary();
            $table->string('title');
            $table->timestamps();
        });
    }

    public function test_save_and_find(): void
    {
        $driver = $this->getSqliteDriver();
        // use $driver or $this->dataManager() for ORM operations

        $pdo = $this->getPdo();
        $pdo->exec("INSERT INTO posts (uuid, title) VALUES ('1', 'Hello')");

        $row = $pdo->query("SELECT * FROM posts WHERE uuid = '1'")->fetch();
        $this->assertSame('Hello', $row['title']);
    }
}

DataTestCase methods

Method Returns
getSqliteDriver() SqliteDriver (in-memory SQLite)
getJsonDriver() JsonFileDriver (temp directory)
dataManager() DataManager with both drivers registered
createTable(string $name, callable $cb) Creates table via Schema builder
getPdo() Raw \PDO instance

preflow/testing 适用场景与选型建议

preflow/testing 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 preflow/testing 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 preflow/testing 我们能提供哪些服务?
定制开发 / 二次开发

基于 preflow/testing 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-10