PHPackages                             mongator/factory - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mongator/factory

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mongator/factory
================

v1.0.2(12y ago)31.8k4PHPPHP &gt;=5.3.0

Since May 27Pushed 12y ago2 watchersCompare

[ Source](https://github.com/mongator/factory)[ Packagist](https://packagist.org/packages/mongator/factory)[ Docs](http://github.com/mongator/factory)[ RSS](/packages/mongator-factory/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (1)Dependencies (2)Versions (4)Used By (0)

Mongator Factory [![Build Status](https://camo.githubusercontent.com/49900c8f1fbdcbdf1814faa83c77e97acf17b63e901302857a6bdc24b921150a/68747470733a2f2f7472617669732d63692e6f72672f6d6f6e6761746f722f666163746f72792e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/mongator/factory)
================================================================================================================================================================================================================================================================================================

[](#mongator-factory-)

Mongator Factory is an alternative to using database fixtures in your PHP unit tests. Instead of maintaining separate files of data, you define a blueprint for each table and then create as many different objects as you need in your PHP code.

By using a database factory instead of fixtures, your unit tests will be clearer and easier to write. You’ll also be able to change the objects you create programmatically instead of being stuck with the same old fixtures.

Mongator Factory will read the Mondator configClass definitions and make a default for every field. If you are using symfony/validator you will also get the mandatory fields of your classes.

Mongator Factory is heavily inspired by [phactory](http://phactory.org/).

Requirements
------------

[](#requirements)

- PHP 5.3.x;
- mongator/mongator
- fzaninotto/faker &gt;= 1.1

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

[](#installation)

The recommended way of installing Mongator Factory is [through composer](http://getcomposer.org). You can see [package information on Packagist.](https://packagist.org/packages/mongator/factory)

```
{
    "require": {
        "mongator/factory": "dev-master"
    }
}
```

Usage
-----

[](#usage)

You can use Mongator Factory with PHPUnit, SimpleTest, or any other PHP unit test framework.

After giving Mongator Factory a mongator instance and a faker instance (faker will generate random string and numbers) you’ll define a blueprint for each model you want to create documents in. The blueprint provides default values for some or all of the columns in that collection. You can then create one or more document in that collection, and optionally override the default values for each one.

Instanciate a MandangoFactory in your setUp method at TestCase and a recall in your tearDown method if you want delete all documents after every test.

```
class TestCase extends \PHPUnit_Framework_TestCase {
    protected $factory;

    protected function setUp() {
        $faker = Faker\Factory::create();
        $this->factory = new Mongator\Factory\Factory($mongator, $faker);
    }

    protected function tearDown() {
        $this->factory->recall();
    }
}
```

On your test cases, just define a new fixture so you can create all the documents you need

```
$this->factory->define('MyFixture', 'Model\Article');
$document = $this->factory->create('MyFixture');
```

And maybe with some default values

```
$this->factory->define('MyFixture', 'Model\Article', array(
    'points' => 2,
    'text' => 'faker::paragraph(2)',
    'line' => 'faker::name',
    'title' => 'text example %s',
    'updatedAt' => '1st May 2010, 01:30:00',
    'votes' => function () { return rand(200, 300); }
));
$document = $this->factory->create('Article');
```

Or the quick way

```
$document = $this->factory->quick('Model\Article');
```

Tests
-----

[](#tests)

Tests are in the `tests` folder. To run them, you need PHPUnit. Example:

```
$ phpunit --configuration phpunit.xml.dist

```

License
-------

[](#license)

MIT, see [LICENSE](LICENSE)

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 87% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~141 days

Total

3

Last Release

4500d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1573114?v=4)[Máximo Cuadros](/maintainers/mcuadros)[@mcuadros](https://github.com/mcuadros)

---

Top Contributors

[![mcuadros](https://avatars.githubusercontent.com/u/1573114?v=4)](https://github.com/mcuadros "mcuadros (67 commits)")[![filiptc](https://avatars.githubusercontent.com/u/2487390?v=4)](https://github.com/filiptc "filiptc (5 commits)")[![dripolles](https://avatars.githubusercontent.com/u/768061?v=4)](https://github.com/dripolles "dripolles (3 commits)")[![wildsurfer](https://avatars.githubusercontent.com/u/1456389?v=4)](https://github.com/wildsurfer "wildsurfer (2 commits)")

### Embed Badge

![Health badge](/badges/mongator-factory/health.svg)

```
[![Health](https://phpackages.com/badges/mongator-factory/health.svg)](https://phpackages.com/packages/mongator-factory)
```

###  Alternatives

[bheller/images-generator

Generator of placeholder images for Faker

573.1M3](/packages/bheller-images-generator)[digilist/snakedumper

4946.0k](/packages/digilist-snakedumper)[swekaj/cron-expression-generator

Generate valid cron expressions.

1169.6k1](/packages/swekaj-cron-expression-generator)[hydreflab/jedi-faker

Faker extension for Star Wars junkie

1430.1k1](/packages/hydreflab-jedi-faker)[gourmet/faker

Faker support for CakePHP 3

189.4k1](/packages/gourmet-faker)[andrefigueira/blog-article-faker

Generate random blog article titles and content (including markdown) using faker

1415.0k](/packages/andrefigueira-blog-article-faker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
