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.
Installation Add the package via Composer:
composer require tipowerup/testbench --dev
Publish the configuration (if needed):
php artisan vendor:publish --provider="TI\PowerUp\Testbench\TestbenchServiceProvider"
First Test
Create a basic test file in tests/Feature/ (e.g., MyExtensionTest.php):
use TI\PowerUp\Testbench\TestCase;
class MyExtensionTest extends TestCase
{
public function test_basic_extension()
{
$this->assertTrue(true); // Replace with your extension logic
}
}
Key Configuration
Check config/testbench.php for:
extensions (list of PowerUp extensions to load in tests).dual_mode (host app or standalone CI).database (test DB settings).// tests/Feature/ExampleExtensionTest.php
use TI\PowerUp\Testbench\TestCase;
class ExampleExtensionTest extends TestCase
{
protected function getExtensions()
{
return ['TI\PowerUp\ExampleExtension'];
}
public function test_extension_works()
{
$response = $this->get('/example-route');
$response->assertStatus(200);
}
}
// config/testbench.php
'dual_mode' => [
'host_app' => true,
'standalone_ci' => false,
],
// Useful for CI-only tests
$this->actingAsStandaloneCI()->get('/api/endpoint');
getExtensions():
protected function getExtensions()
{
return [
'TI\PowerUp\AuthExtension',
'TI\PowerUp\MediaExtension',
];
}
$this->loadExtensions(['TI\PowerUp\DebugExtension'])->testDebugTools();
public function test_database_operations()
{
$this->artisan('migrate:fresh')
->assertExitCode(0);
}
$user = User::factory()->create();
$this->actingAs($user)->get('/profile')->assertOk();
public function test_api_endpoint()
{
$response = $this->postJson('/api/powerup', ['key' => 'value'])
->assertCreated();
}
$this->withHeaders(['X-PowerUp-Token' => 'test'])
->get('/protected-route')
->assertOk();
protected function setUp(): void
{
$this->app->bind('TI\PowerUp\Contracts\ExampleService', function () {
return new MockExampleService();
});
}
public function test_extension_event()
{
Event::fake();
$this->artisan('powerup:event-trigger');
Event::assertDispatched(PowerUpEvent::class);
}
Extension Conflicts
getExtensions() to explicitly define dependencies and test them in isolation.Database State
migrate:fresh or refresh in setUp():
public function setUp(): void
{
parent::setUp();
$this->artisan('migrate:fresh');
}
Dual-Mode Misconfiguration
if ($this->isStandaloneCI()) {
$this->testCIOnlyFeatures();
} else {
$this->testHostAppFeatures();
}
Service Provider Booting
config/testbench.php under extensions.Environment Variables
.env.testing may not be loaded.APP_ENV=testing in phpunit.xml:
<env name="APP_ENV" value="testing"/>
Enable Debug Mode
Add to phpunit.xml:
<env name="APP_DEBUG" value="true"/>
Log Output Use Laravel’s logging:
\Log::debug('Test debug info', ['data' => $this->someData]);
Dump Variables
Use dd() or dump() in tests (but avoid in CI):
$this->dump($this->app->make('TI\PowerUp\ExampleService'));
Testbench Artisan Commands Run custom Artisan commands in tests:
$this->artisan('powerup:check')
->expectsOutput('Extension is ready')
->assertExitCode(0);
Custom Test Cases
Extend TestCase for reusable logic:
class PowerUpTestCase extends TestCase
{
protected function assertExtensionLoaded(string $extension)
{
$this->assertTrue(class_exists($extension));
}
}
Mocking PowerUp Services Use Laravel’s mocking tools:
$mock = Mockery::mock('TI\PowerUp\Contracts\ExampleService');
$this->app->instance('TI\PowerUp\Contracts\ExampleService', $mock);
Custom Assertions Add assertions for PowerUp-specific logic:
public function assertPowerUpResponse($response, $expected)
{
$response->assertJsonStructure(['data', 'meta']);
$this->assertEquals($expected, $response->json('data'));
}
CI-Specific Tests
Use isStandaloneCI() to skip host-app-only tests in CI:
if (!$this->isStandaloneCI()) {
$this->testHostAppIntegration();
}
How can I help you explore Laravel packages today?