zenstruck/foundry
Zenstruck Foundry is a Laravel-friendly factory and fixtures toolkit for building and persisting test data. Define model factories, create realistic related objects, seed databases, and write cleaner, faster tests with helpers for states, Faker, and repositories.
Strengths:
withoutDoctrineEvents. This reduces flakiness in isolated unit tests where Doctrine events (e.g., prePersist, postLoad) might interfere.withoutDoctrineEvents demonstrates Foundry’s attention to edge cases in Symfony/Doctrine integration, reinforcing its suitability for Laravel’s Eloquent-based applications.Potential Gaps:
HasFactory, Faker integration). The new release does not address this.laravel-shift/database remains manual.High: The new release is a minor fix and does not alter the core integration approach. Foundry remains a natural fit for Laravel’s Eloquent/Doctrine stack.
withoutDoctrineEvents fix is particularly valuable for unit tests where Doctrine events could introduce unintended side effects. This aligns with Laravel’s testing best practices (e.g., isolating unit tests from ORM behavior).Customization Needs:
withoutDoctrineEvents in unit tests to avoid event-related issues. This could require updating test suites to opt into this behavior where needed.Faker seeds).Factory will adapt to Foundry’s stateful paradigm with minimal additional effort.RefreshDatabase or MigrateFresh?withoutDoctrineEvents be enabled by default in unit tests, or only opt-in? How will this interact with Laravel’s DatabaseTransactions or RefreshDatabase?withoutDoctrineEvents in unit tests? Should this be wrapped in a Laravel-specific helper (e.g., unitTest() trait)?withoutDoctrineEvents affect these?Core Stack:
withoutDoctrineEvents fix improves compatibility for unit tests, where Doctrine events are often undesirable.Compatibility:
HasFactory trait via custom wrappers.Faker integration or other Laravel-specific tools.Loader.Factory classes.withoutDoctrineEvents usage in unit tests. Example:
// In a custom test trait
trait UnitTestTrait {
protected function withoutDoctrineEvents(): void {
Foundry::withoutDoctrineEvents();
}
}
Use this trait in unit test classes to ensure consistent event handling.RefreshDatabase.Laravel-Specific Adjustments:
withoutDoctrineEvents usage in unit tests. Example:
// app/Traits/UnitTestTrait.php
use Zenstruck\Foundry\Test\TestCase;
trait UnitTestTrait {
public function setUp(): void {
parent::setUp();
if ($this instanceof TestCase && $this->usesUnitTests()) {
Foundry::withoutDoctrineEvents();
}
}
}
createModel()).Tooling:
withoutDoctrineEvents in unit test phases if needed.withoutDoctrineEvents in unit tests. Start with a small subset of tests to validate behavior.withoutDoctrineEvents, adding a minor cognitive load for unit tests.withoutDoctrineEvents in Laravel’s test case base class). A custom trait/macro will be needed.Developer Onboarding:
withoutDoctrineEvents, including:
## Unit Test Best Practices with Foundry
To avoid Doctrine event interference in unit tests, use:
```php
use App\Traits\UnitTestTrait;
class UserTest extends TestCase {
use UnitTestTrait;
// Events are automatically disabled in setUp()
}
withoutDoctrineEvents.Debugging:
withoutDoctrineEvents is working as expected. Example:
$this->assertFalse(Foundry::hasDoctrineEventsEnabled());
How can I help you explore Laravel packages today?