Reusable test utilities to validate a Laravel project's Chief setup.
- All registered Chief resources and fragments.
- Two test modes:
generated: create/update/delete flows where possible.existing: read-only checks on existing database records.
- Unsupported scenarios are skipped with a clear reason.
In your Laravel project:
composer require --dev thinktomorrow/chief-testingWhen working locally from a path repository, add this in your project's composer.json first:
{
"repositories": [
{
"type": "path",
"url": "../../packages/chief-testing",
"options": { "symlink": true }
}
]
}Then install:
composer require --dev thinktomorrow/chief-testing:dev-mainRun the installer command in your project:
php artisan chief-testing:installThis generates:
tests/Feature/Chief/ChiefResourceSetupTest.phptests/Feature/Chief/ChiefFragmentSetupTest.php
Available options:
php artisan chief-testing:install --force
php artisan chief-testing:install --path=tests/Feature/Chief --namespace="Tests\\Feature\\Chief"If you prefer, you can also create the two test files manually.
tests/Feature/Chief/ChiefResourceSetupTest.php:
<?php
declare(strict_types=1);
namespace Tests\Feature\Chief;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\CreatesApplication;
use Thinktomorrow\Chief\Testing\Feature\ChiefResourceSetupTestCase;
final class ChiefResourceSetupTest extends ChiefResourceSetupTestCase
{
use CreatesApplication;
use RefreshDatabase;
protected function authenticateChiefAdmin(): void
{
// Optional: login a chief admin user when routes are protected.
// Example:
// $admin = \App\Models\User::factory()->create();
// $this->actingAs($admin, 'chief');
}
}tests/Feature/Chief/ChiefFragmentSetupTest.php:
<?php
declare(strict_types=1);
namespace Tests\Feature\Chief;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\CreatesApplication;
use Thinktomorrow\Chief\Testing\Feature\ChiefFragmentSetupTestCase;
final class ChiefFragmentSetupTest extends ChiefFragmentSetupTestCase
{
use CreatesApplication;
use RefreshDatabase;
protected function authenticateChiefAdmin(): void
{
// Optional: login a chief admin user when routes are protected.
}
}Run both suites:
php artisan test --compact tests/Feature/ChiefRun only resources:
php artisan test --compact tests/Feature/Chief/ChiefResourceSetupTest.phpRun only fragments:
php artisan test --compact tests/Feature/Chief/ChiefFragmentSetupTest.phpEnvironment variables:
CHIEF_TEST_MODE=generated|existingCHIEF_EXISTING_DB_CONNECTION=<connection-name>CHIEF_EXISTING_LIMIT_PER_RESOURCE=5CHIEF_EXISTING_LIMIT_PER_FRAGMENT=10
Database connection resolution in existing mode:
CHIEF_EXISTING_DB_CONNECTIONDB_CONNECTIONfrom.env.testingDB_CONNECTIONfrom.env
Run read-only checks on real existing data:
CHIEF_TEST_MODE=existing php artisan test --compact tests/Feature/Chief- Existing mode enforces a read-only SQL guard and blocks write queries.
- Generated mode uses available factories/setup and skips unsupported resources/fragments with reason.
- Base test cases provided by this package:
Thinktomorrow\Chief\Testing\Feature\ChiefResourceSetupTestCaseThinktomorrow\Chief\Testing\Feature\ChiefFragmentSetupTestCase