PHPackages                             noj/fabrica - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. noj/fabrica

ActiveLibrary[Testing &amp; Quality](/categories/testing)

noj/fabrica
===========

Library to create entity factories for testing

1.2.1(7mo ago)69.6kMITPHPPHP ^8.0CI passing

Since Apr 20Pushed 7mo ago2 watchersCompare

[ Source](https://github.com/jonnyynnoj/fabrica)[ Packagist](https://packagist.org/packages/noj/fabrica)[ RSS](/packages/noj-fabrica/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (4)Versions (15)Used By (0)

Fabrica
=======

[](#fabrica)

[![Pipeline](https://camo.githubusercontent.com/248067311f5c7d01592113a80d2d98fd5615d0d19453a61b850ea9a599648796/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6f6e6e79796e6e6f6a2f666162726963612f74657374732e796d6c3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/248067311f5c7d01592113a80d2d98fd5615d0d19453a61b850ea9a599648796/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6a6f6e6e79796e6e6f6a2f666162726963612f74657374732e796d6c3f7374796c653d666c61742d737175617265)[![Latest Stable Version](https://camo.githubusercontent.com/6cef403ddf79dff4971bf2238d62497798da0411679277df600d5399b096686d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6e6f6a2f666162726963613f7374796c653d666c61742d737175617265)](https://packagist.org/packages/noj/fabrica)[![PHP Version Support](https://camo.githubusercontent.com/f6c4a22d8c320c2c4e0867ee45ebf2d96b089a3ccd3c549a149d797b8f4d661b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e6f6a2f666162726963613f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f6c4a22d8c320c2c4e0867ee45ebf2d96b089a3ccd3c549a149d797b8f4d661b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6e6f6a2f666162726963613f7374796c653d666c61742d737175617265)[![GitHub](https://camo.githubusercontent.com/d554141cd000f0fbc1ef16b1be14b19dd90e25f6d605fb7fa233ff0759d2d9eb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f6e6e79796e6e6f6a2f666162726963613f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/d554141cd000f0fbc1ef16b1be14b19dd90e25f6d605fb7fa233ff0759d2d9eb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f6a6f6e6e79796e6e6f6a2f666162726963613f7374796c653d666c61742d737175617265)[![Total Downloads](https://camo.githubusercontent.com/143c3837473a4e831f6c07370ee5e68a71701511d59a38938cecafbe90d25ec8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6e6f6a2f666162726963613f7374796c653d666c61742d737175617265)](https://packagist.org/packages/noj/fabrica)

Fabrica handles the definition and creation of objects for use in testing.

Coupled with its Doctrine integration, Fabrica allows you to fully test CRUD logic without mocking. See the [What Problem Does it Solve?](https://github.com/jonnyynnoj/fabrica/wiki/What-Problem-Does-it-Solve%3F) page for a full explanation.

---

- [Installing](#installing)
- [Usage](#usage)
    - [Setup](#setup)
    - [Basic Usage](#basic-usage)
    - [Setters](#setters)
    - [Overrides](#overrides)
    - [Create Multiple](#create-multiple)
    - [Relations](#relations)
        - [Overriding Relation Properties](#overriding-relation-properties)
    - [Entity Types](#entity-types)
        - [Extending](#extending)
    - [Doctrine Integration](#doctrine-integration)
        - [Refreshing the Database Between Tests](#refreshing-the-database-between-tests)
        - [PHPUnit Assertions](#phpunit-assertions)
    - [Faker Integration](#faker-integration)
- [Inspirations](#inspirations)

Installing
----------

[](#installing)

```
composer require noj/fabrica --dev

```

Usage
-----

[](#usage)

### Setup

[](#setup)

First initialise Fabrica somewhere within your test suite. For PHPUnit, this can be done using the [bootstrap](https://phpunit.readthedocs.io/en/9.1/organizing-tests.html?highlight=bootstrap#composing-a-test-suite-using-xml-configuration) option:

```
