Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
F

foundry

> 编程语言
Open source

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

796 stars0 likes1 views
WebsiteGitHub

About

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

Foundry

"Fixtures you'll actually enjoy writing!"

Foundry turns fixture creation into a joy, via an expressive, auto-completable, on-demand fixtures system with Symfony and Doctrine:

php
$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

Upgrade guide to v2

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.

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

You can start the containers and run the test suite:

bash
# start the container
$ docker compose up --detach

# install dependencies
$ composer update

# run main testsuite (with "schema" reset database strategy)
$ ./phpunit

# run "reset-database" testsuite
$ ./phpunit --testsuite reset-database

Overriding the default configuration

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

…

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:

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

services:
    mysql:
        ports:
            - "3308:3306"
dotenv
# .env.local
DATABASE_URL="mysql://root:[email protected]:3308/foundry_test?serverVersion=5.7.42"

Run the tests locally faster

As long as you don't want to test Mongo, you can use the following .env.local file to run the tests faster locally:

dotenv
# dama/doctrine-test-bundle makes Foundry testsuite really faster
USE_DAMA_DOCTRINE_TEST_BUNDLE="1"

# using both ODM and ORM makes the "reset db" mechanism slower
MONGO_URL=""

# Use the last version of PHPUnit
PHPUNIT_VERSION="12"

# Enable all features of Foundry
USE_FOUNDRY_PHPUNIT_EXTENSION="1"

"maker" tests are also quite slow, so you can skip them with using the following command:

bash
$ ./phpunit --exclude-group=maker

Enjoy blazing fast tests! :rocket:

Running the documentation linter locally

This section provides guidance on how to run the documentation linter, contained within a Docker image, locally on your machine. This linter is designed to verify and ensure that the document syntax adheres to the required standards.

The following command runs the linter in the local directory:

bash
docker run --rm -it -e DOCS_DIR='/docs' -v ${PWD}/docs:/docs  oskarstark/doctor-rst:latest

Credit

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.

Security Policy

If you discover a security vulnerability, please do not open a public issue or pull request. Instead, please review this repository's Security Policy for instructions on how to report it responsibly.

Issues· 26 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPdoctrinefactoryfakerfixtures

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言