tipowerup/testbench
Shared Orchestra Testbench foundation for TastyIgniter v4 extensions. Boots full Laravel + TI context for tests with zero duplication: SQLite in-memory DB, array cache, core system tables/migrations, TI providers, temp paths, and extension scanning disabled for isolation.
Shared testing foundation for TI PowerUp TastyIgniter v4 extensions. Provides full Laravel + TastyIgniter context in tests via Orchestra Testbench, with zero duplication across extensions.
composer require --dev tipowerup/testbench
Each extension needs three changes:
phpunit.xml.distPoint 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>
tests/TestCase.phpExtend 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];
}
}
tests/Pest.phpBind the TestCase to your test directories:
<?php
declare(strict_types=1);
uses(Tipowerup\MyExtension\Tests\TestCase::class)->in('Feature');
uses()->in('Unit');
Every test extending the testbench TestCase automatically receives:
:memory: database with foreign key constraintssettings, extensions, extension_settings, etc.)Igniter\Flame\ServiceProvider registered (cascades to all TI core providers)autoloadExtensions(false))If your test doesn't need TI core tables, set $runCoreMigrations = false:
abstract class TestCase extends BaseTestCase
{
protected bool $runCoreMigrations = false;
// ...
}
Admin migrations (orders, menus, locations) are opt-in because some are SQLite-incompatible:
protected function setUp(): void
{
parent::setUp();
$this->runTiAdminMigrations();
}
protected function setUp(): void
{
parent::setUp();
$this->runExtensionMigrations(__DIR__.'/../database/migrations');
}
TestsMigrationsMigration 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']);
TestsTIIntegrationTastyIgniter 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']);
MocksTIServicesPre-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']);
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.
# Run tests
composer test:pest
# Fix code style
composer test:lint-fix
# Run all checks
composer test
MIT License. See LICENSE for details.
How can I help you explore Laravel packages today?