Tip
First time on v2? See What's new in v2 for a single-page tour of the new surface.
First stable of the v2 line. Per-prerelease notes (linked below) carry the full fix-by-fix detail.
Highlights
- Immutable factory API:
new(),from(),count(),build()/buildMany(),save()/saveMany(), with a read/query split viaquery()andtable(). - Directional association DSL
for()/has(), with alias-explicit overloads (->for($f, 'BusinessAddress')) to disambiguate same-target associations. withRequiredParents()composes exactly the NOT NULLbelongsToparents a schema requires, withrequiredParentAssociations()/excludedRequiredParentAssociations()hooks for fine control.recycle($entity)reuses a built parent wherever abelongsToin the build graph targets its source table — closing the silent N× duplicate-parent footgun.Sequencecontext object passed tosequence()callables (index,position,total,isFirst,isLast,factory,generator); plus the lightersequenceField()for varying a single field across rows.TableAssertionsTrait—assertTableHas/Missing/Count/Empty,assertEntityExists/MissingoverFactory::query()with sharp failure messages.Storyscenario abstract with named entity pools (addToPool,getPool,getRandom,getRandomSet), backwards-compatible with existingFixtureScenarioInterface.state()/ named states andafterBuild()/afterSave()lifecycle hooks;has()now carries pivot data onto the join row.strictDefinitiondetector deprecates FK columns set indefinition()(names column, alias, migration path); opt-out via Configure mid-migration.- Eager
FactoryTransactionStrategyby default for leak-safe mixed Factory/direct-save tests, withLazyFactoryTransactionStrategy/LazyTransactionTraitopt-outs. - Improved Bake output for the v2 API; bundled Rector ruleset for mechanical 1.x call-site upgrades.
Breaking changes (from 1.x)
- 1.x deprecated wrappers removed. Migrate to latest 1.x first, then to 2.x — use the bundled
rector.php. - API renames:
make()→new(),makeMany()→count()+buildMany()/saveMany(),makeFrom()→from(),persist()/persistEntities()→save()/saveMany(),Factory::get()→Factory::table()->get(),Factory::find()→Factory::query(). - Generator property access → method access (
$generator->name→$generator->name()); Rector-rewritten. enumElement()removed — useenumCase()/enumValue()(no Rector rewrite).FactoryTransactionStrategynow eager by default (1.x was lazy): opens a transaction on the primary test connection. Opt into lazy viaLazyFactoryTransactionStrategy/LazyTransactionTrait.
Since 2.0.0-rc.4
- Fix
strictDefinitionexempting shared-primary-key 1:1belongsToFKs (childidthat is both PK and FK escaped the deprecation) (#108). - Friendlier
requiredParentAssociations()hook errors for unknown and non-belongsToaliases (#109).
Prerelease detail
rc.4 · rc.3 · rc.2 · rc.1 · beta.3 · beta.2 · beta.1
Full Changelog: 1.4.3...2.0.0