PHPackages                             ergebnis/factory-bot - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ergebnis/factory-bot

ActiveLibrary[Database &amp; ORM](/categories/database)

ergebnis/factory-bot
====================

Provides a fixture factory for doctrine/orm entities.

1.10.0(8mo ago)81702.8k↑30.9%5[2 PRs](https://github.com/ergebnis/factory-bot/pulls)MITPHPPHP ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0 || ~8.5.0CI passing

Since Jul 9Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/ergebnis/factory-bot)[ Packagist](https://packagist.org/packages/ergebnis/factory-bot)[ Docs](https://github.com/ergebnis/factory-bot)[ RSS](/packages/ergebnis-factory-bot/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (22)Versions (42)Used By (0)

factory-bot
===========

[](#factory-bot)

[![Integrate](https://github.com/ergebnis/factory-bot/workflows/Integrate/badge.svg)](https://github.com/ergebnis/factory-bot/actions)[![Merge](https://github.com/ergebnis/factory-bot/workflows/Merge/badge.svg)](https://github.com/ergebnis/factory-bot/actions)[![Release](https://github.com/ergebnis/factory-bot/workflows/Release/badge.svg)](https://github.com/ergebnis/factory-bot/actions)[![Renew](https://github.com/ergebnis/factory-bot/workflows/Renew/badge.svg)](https://github.com/ergebnis/factory-bot/actions)

[![Code Coverage](https://camo.githubusercontent.com/e7e51dfe915af7cc4f8acede6fc38b2e9dc3aea078d1ba5a7a1cd2028832e443/68747470733a2f2f636f6465636f762e696f2f67682f65726765626e69732f666163746f72792d626f742f6272616e63682f6d61696e2f67726170682f62616467652e737667)](https://codecov.io/gh/ergebnis/factory-bot)

[![Latest Stable Version](https://camo.githubusercontent.com/79b9f9dfa51f21cd40dbc42def2248cc12d1daa9da386e9cafd102d576debff4/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f666163746f72792d626f742f762f737461626c65)](https://packagist.org/packages/ergebnis/factory-bot)[![Total Downloads](https://camo.githubusercontent.com/bca030faf656808a9db0ef6f60a6474e92e1915aedc2988675f95d4b5076032d/68747470733a2f2f706f7365722e707567782e6f72672f65726765626e69732f666163746f72792d626f742f646f776e6c6f616473)](https://packagist.org/packages/ergebnis/factory-bot)[![Monthly Downloads](https://camo.githubusercontent.com/c2566c6186b8d8f67f23fda1ccea194d64f31dbdd8c73175db2a1e6f42cdd6bd/687474703a2f2f706f7365722e707567782e6f72672f65726765626e69732f666163746f72792d626f742f642f6d6f6e74686c79)](https://packagist.org/packages/ergebnis/factory-bot)

This project provides a [`composer`](https://getcomposer.org) package with a fixture factory for [`doctrine/orm`](https://github.com/doctrine/orm) entities.

Installation
------------

[](#installation)

Run

```
composer require --dev ergebnis/factory-bot
```

Usage
-----

[](#usage)

The entry point of `ergebnis/factory-bot` is the [`FixtureFactory`](src/FixtureFactory.php).

You will use the fixture factory to create entity definitions and to create Doctrine entities populated with fake data.

- [Examples](#examples)
- [Creating a fixture factory](#creating-a-fixture-factory)
- [Creating entity definitions](#creating-entity-definitions)
- [Loading entity definitions](#loading-entity-definitions)
- [Registering entity definitions](#registering-entity-definitions)
- [Creating entities](#creating-entities)
- [Persisting entities](#persisting-entities)
- [Flushing entities](#flushing-entities)

### Examples

[](#examples)

You can find examples in

- the directory [`example/`](example/)
- the repository [`ergebnis/factory-bot-example`](https://github.com/ergebnis/factory-bot-example)

### Creating a fixture factory

[](#creating-a-fixture-factory)

The fixture factory requires an instance of `Doctrine\ORM\EntityManagerInterface` (for reading class metadata from Doctrine entities, and for persisting Doctrine entities when necessary) and an instance of `Faker\Generator` for generating fake data.

```
