A model factory library for creating expressive, auto-completable, on-demand dev/test fixtures with Symfony and Doctrine.

Fund package maintenance!

Installs: 4 029 013

Dependents: 57

Suggesters: 1

Security: 0

Stars: 575

Watchers: 10

Forks: 55

Open Issues: 65

v1.37.0 2024-03-20 15:09 UTC


CI Status Code Coverage Latest Version Downloads

Foundry makes creating fixtures data fun again, via an expressive, auto-completable, on-demand fixtures system with Symfony and Doctrine:

$post = PostFactory::new() // Create the factory for Post objects
    ->published()          // Make the post in a "published" state
    ->create([             // create & persist the Post object
        'slug' => 'post-a' // This Post object only requires the slug field - all other fields are random data

The factories can be used inside DoctrineFixturesBundle to load fixtures or inside your tests, where it has even more features.

Foundry supports doctrine/orm (with doctrine/doctrine-bundle), doctrine/mongodb-odm (with doctrine/mongodb-odm-bundle) or a combination of these.

Want to watch a screencast 🎥 about it? Check out https://symfonycasts.com/foundry

Read the Documentation

How to contribute

Running the Test Suite

The test suite of this library needs one or more databases, then it comes with a docker compose configuration.


Docker and PHP installed locally (with mysql, pgsql & mongodb extensions) is required.

You can start the containers and run the test suite:

# start the container
$ docker compose up --detach

# install dependencies
$ composer update

# run test suite with all available permutations
$ composer test

# run only one permutation
$ vendor/bin/phpunit

# run test suite with dama/doctrine-test-bundle
$ vendor/bin/phpunit -c phpunit.dama.xml.dist

# run test suite with postgreSQL instead of MySQL
$ DATABASE_URL="postgresql://zenstruck:zenstruck@" vendor/bin/phpunit

Overriding the default configuration

You can override default environment variables by creating a .env.local file, to easily enable permutations:

# .env.local

# run test suite with postgreSQL
$ vendor/bin/phpunit

The .env.local file can also be used to override the port of the database containers, if it does not meet your local requirements. You'll also need to override docker compose configuration:

Here is an example to use MySQL on port 3308:

# docker-compose.override.yml
version: '3.9'

            - "3308:3306"
# .env.local


The AAA style of testing was first introduced to me by Adam Wathan's excellent Test Driven Laravel Course. The inspiration for this libraries API comes from Laravel factories and christophrumpel/laravel-factories-reloaded.