tipowerup/testbench 问题修复 & 功能扩展

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

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

tipowerup/testbench

Composer 安装命令:

composer require tipowerup/testbench

包简介

Shared testing foundation for TI PowerUp extensions. Provides full Laravel + TastyIgniter context in tests with dual-mode support (host app and standalone CI).

README 文档

README

Shared testing foundation for TI PowerUp TastyIgniter v4 extensions. Provides full Laravel + TastyIgniter context in tests via Orchestra Testbench, with zero duplication across extensions.

Requirements

  • PHP ^8.3
  • TastyIgniter Core ^v4.0

Installation

composer require --dev tipowerup/testbench

Setup

Each extension needs three changes:

1. phpunit.xml.dist

Point the bootstrap to the testbench:

<phpunit bootstrap="vendor/tipowerup/testbench/src/bootstrap.php"
         colors="true"
         cacheDirectory=".phpunit.cache">
    <testsuites>
        <testsuite name="Tests">
            <directory>tests</directory>
        </testsuite>
    </testsuites>
    <source>
        <include>
            <directory>src</directory>
        </include>
    </source>
</phpunit>

2. tests/TestCase.php

Extend the testbench TestCase and implement the two abstract methods:

<?php

declare(strict_types=1);

namespace Tipowerup\MyExtension\Tests;

use Tipowerup\Testbench\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
    protected function getExtensionBasePath(): string
    {
        return dirname(__DIR__);
    }

    protected function getExtensionProviders(): array
    {
        return [\Tipowerup\MyExtension\Extension::class];
    }
}

3. tests/Pest.php

Bind the TestCase to your test directories:

<?php

declare(strict_types=1);

uses(Tipowerup\MyExtension\Tests\TestCase::class)->in('Feature');
uses()->in('Unit');

What You Get

Every test extending the testbench TestCase automatically receives:

  • SQLite :memory: database with foreign key constraints
  • Array cache driver for isolation
  • TI core system tables (settings, extensions, extension_settings, etc.)
  • Igniter\Flame\ServiceProvider registered (cascades to all TI core providers)
  • Extension filesystem scanning disabled (autoloadExtensions(false))
  • Temp directories for extensions/themes/temp paths (auto-cleaned)

Disabling Core Migrations

If your test doesn't need TI core tables, set $runCoreMigrations = false:

abstract class TestCase extends BaseTestCase
{
    protected bool $runCoreMigrations = false;

    // ...
}

Running Admin Migrations

Admin migrations (orders, menus, locations) are opt-in because some are SQLite-incompatible:

protected function setUp(): void
{
    parent::setUp();

    $this->runTiAdminMigrations();
}

Running Extension Migrations

protected function setUp(): void
{
    parent::setUp();

    $this->runExtensionMigrations(__DIR__.'/../database/migrations');
}

Traits

TestsMigrations

Migration quality assertions:

use Tipowerup\Testbench\Concerns\TestsMigrations;

// Assert migrate up creates tables, rollback removes them
$this->assertMigrationCycle($path, ['my_table', 'my_other_table']);

// Assert N up/down cycles succeed without errors
$this->assertSurvivesInstallCycles($path, ['my_table'], cycles: 3);

// Assert migrations don't touch core TI tables
$this->assertNoCoreTables($path);

// Assert all migrations have non-empty down() methods
$this->assertProperDownMethods($path);

// Assert schema accepts seed data after rollback+migrate
$this->assertSchemaAcceptsSeedData($path, 'my_table', ['name' => 'test'], ['name']);

TestsTIIntegration

TastyIgniter integration assertions:

use Tipowerup\Testbench\Concerns\TestsTIIntegration;

$this->assertParamsWork('my_key', 'my_value');
$this->assertExtensionRegistered('tipowerup.myextension');
$this->assertTIInstallCycle('tipowerup.myextension');
$this->assertCleanPurge('tipowerup.myextension', ['my_table']);
$this->assertNavigationRegistered(Extension::class, 'tools', 'my-item');
$this->assertPermissionsRegistered(Extension::class, ['Tipowerup.MyExtension.Manage']);

MocksTIServices

Pre-built mock factories with sensible defaults:

use Tipowerup\Testbench\Concerns\MocksTIServices;

// Mock with defaults
$mock = $this->mockExtensionManager();

// Override specific stubs
$mock = $this->mockExtensionManager(['hasExtension' => false]);

// Available mocks
$this->mockExtensionManager($overrides);
$this->mockHubManager($overrides);
$this->mockUpdateManager($overrides);
$this->mockPackageManifest($overrides);
$this->mockService(MyService::class, ['method' => 'return_value']);

Dual-Mode Bootstrap

The bootstrap auto-detects the environment:

Mode Condition Use Case
Host Parent TI project found (artisan + vendor/tastyigniter/core/) Local dev inside a TI app
Standalone No parent TI project CI pipelines, independent dev

Both modes use Orchestra Testbench identically. The mode is available via $this->getTestbenchMode() for extensions that need conditional behavior.

Development

# Run tests
composer test:pest

# Fix code style
composer test:lint-fix

# Run all checks
composer test

License

MIT License. See LICENSE for details.

tipowerup/testbench 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 105
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 22
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-12