doctrine/data-fixtures

Manage and load data fixtures for any Doctrine object manager

Library
Composer
v2.2.1
2,852stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
76/100Good
Development Activity84
Maintenance60
Community60
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
81/100Excellent
Architecture85
Code Quality86
Innovation70
Learning Curve82

doctrine/data-fixtures is a library that provides a simple, structured way to define and load data fixtures for Doctrine’s ORM and ODM. Fixtures are plain PHP classes that populate a database (or document store) with known data, which is essential for reproducible tests, local development seeding, and demos.

Beyond basic loading, it supports ordering fixtures explicitly, declaring dependencies between them, sharing entity references across fixtures, purging existing data before loading, and executing everything against any Doctrine object manager. It underpins the popular Symfony DoctrineFixturesBundle and is one of the most widely installed packages in the PHP ecosystem.

What You Get

  • A FixtureInterface and AbstractFixture base for writing fixture classes
  • A Loader that discovers and organizes fixtures from a directory or classes
  • Ordered and dependent fixture execution for correct load sequencing
  • A reference repository for sharing created entities across fixtures
  • Purgers to clear existing data before loading, for both ORM and ODM

Common Use Cases

  • Seeding a database with known data for automated test suites
  • Populating a local development environment with realistic sample data
  • Loading demo data for staging or presentation environments
  • Managing complex, interdependent seed data with a defined load order

Under The Hood

Architecture — The library separates fixture definition from execution. Fixtures implement FixtureInterface (often via AbstractFixture, which adds reference-sharing) and may implement OrderedFixtureInterface or DependentFixtureInterface to control sequencing. A Loader (src/Loader.php) collects fixture instances and resolves their order, an Executor (src/Executor) drives loading against a specific object manager, a Purger (src/Purger) clears existing records first, and a ProxyReferenceRepository lets fixtures store and retrieve created entities by name so later fixtures can reference earlier ones. Events allow hooking into the load lifecycle. Tech Stack — Modern PHP depending on doctrine/persistence for the object-manager abstraction and psr/log, with optional integration for both the Doctrine ORM and MongoDB ODM; tests run under PHPUnit via GitHub Actions CI. Code Quality — A mature, actively maintained codebase (hundreds of commits, ongoing releases) with clear interface segregation (separate interfaces for ordering, dependencies, and shared fixtures), a dedicated exception hierarchy, and comprehensive test coverage. API Design — The API is small and idiomatic: implement load(ObjectManager $manager) in a fixture, optionally add ordering/dependency interfaces, use addReference/getReference to link entities, and run through a Loader and Executor. This composes cleanly and is familiar to Doctrine users, which is why the higher-level Symfony bundle builds directly on it.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search