zenstruck/foundry
Zenstruck Foundry supercharges Laravel/Symfony testing with fluent model factories, fixtures, and story-based data builders. Create, persist, and customize entities easily, manage relations, and write cleaner, faster tests with powerful helpers and states.
Strengths:
create()/factory() methods.StatefulInterface and Doctrine’s ORM, making it a natural fit for Laravel applications using Eloquent (which is Doctrine-based under the hood).User → Post → Comment chains) with minimal configuration.hasPublishedPost(), hasDraftPost()), improving test isolation and readability.Factory classes that may cache or seed globally).Potential Gaps:
HasFactory, Faker integration) may require customization or wrappers.laravel-shift/database.Factory classes (e.g., User::factory()).Loader to register fixtures in tests/TestCase or a dedicated FixtureServiceProvider.State system for complex test scenarios (e.g., user roles, soft-deleted records).Factory in a Laravel-friendly facade or trait (e.g., HasFoundry).State to Laravel’s testing conventions (e.g., createWithStates() helper).DatabaseMigrations or RefreshDatabase traits.Factory will adapt quickly, but Foundry’s stateful approach may require rethinking test organization.RefreshDatabase or MigrateFresh?Loader replace Laravel’s create() helpers, or will a wrapper layer be needed?Faker seeds) may need bridging.Loader or custom test traits.Factory classes with less boilerplate.HasFactory trait via custom trait or macro.DatabaseTransactions or RefreshDatabase.Faker integration may require Foundry’s Faker adapter or custom state definitions.actingAs()) may need Foundry-compatible wrappers.User, Post) with Foundry equivalents.// Before (Laravel Factory)
User::factory()->hasPosts(3)->create();
// After (Foundry)
User::new()->hasPosts(3)->create();
FoundryServiceProvider to register all factories via Foundry’s Loader.Factory classes (use Laravel’s macro() to warn or redirect).// config/foundry.php
'factories' => [
\App\Models\User::class,
\App\Models\Post::class,
],
User::new()->asAdmin()->withPublishedPosts()).RefreshDatabase via Foundry’s Loader::load() in setUp().actingAs() compatibility).Faker support to match Laravel’s Faker seeds.Factory methods (e.g., afterCreating()).createModel(), create()).State methods to enable autocompletion.Loader (e.g., php artisan foundry:load).morphMap or polymorphic relationships.Faker seeds, custom create() logic).Factory calls in tests with Foundry equivalents.macro() to log deprecation warnings).config/foundry.php), reducing duplication.State system and auto-completion rules.tinker support for Foundry fixtures).Foundry::debug(true); // Logs auto-completion steps
How can I help you explore Laravel packages today?