PHPackages                             dmirogin/fakemodel - 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. dmirogin/fakemodel

AbandonedArchivedYii2-extension[Testing &amp; Quality](/categories/testing)

dmirogin/fakemodel
==================

Test helper for Yii2 projects that make and persist models

v0.1.0(8y ago)302736[1 issues](https://github.com/dmirogin/fakemodel/issues)MITPHPPHP &gt;=7.1.0

Since Dec 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/dmirogin/fakemodel)[ Packagist](https://packagist.org/packages/dmirogin/fakemodel)[ RSS](/packages/dmirogin-fakemodel/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)Dependencies (3)Versions (3)Used By (0)

[![Build Status](https://camo.githubusercontent.com/9e36e8240e160e638159112e351f218d3d0ce4b69359747e1fda6ecb71b9146f/68747470733a2f2f7472617669732d63692e6f72672f646d69726f67696e2f66616b656d6f64656c2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/dmirogin/fakemodel)[![Latest Stable Version](https://camo.githubusercontent.com/6c61a3fc57b6a4b9c69110a66b86c2885cabccf0cf8e733c7a365a1fef523508/68747470733a2f2f706f7365722e707567782e6f72672f646d69726f67696e2f66616b656d6f64656c2f762f737461626c65)](https://packagist.org/packages/dmirogin/fakemodel)[![GitHub license](https://camo.githubusercontent.com/887ec8758c0356457079c49372d44144cd3eab3e78e06096cd30f71d3eabd89e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646d69726f67696e2f66616b656d6f64656c2e737667)](https://github.com/dmirogin/fakemodel/blob/master/LICENSE)

This package helps you to manage faked models. Make, create and store in database. This factory is another way to work with fixtures and inspired by factories in laravel.

### Requirements

[](#requirements)

- PHP 7.0 +

### Instalation

[](#instalation)

```
composer require dmirogin/fakemodel
```

### How to use

[](#how-to-use)

1. Add component to your application configuration

    ```
    'factory' => [
        'class' => \dmirogin\fakemodel\ModelFactory::class,
        'resolvers' => [
            [
                'class' => \dmirogin\fakemodel\resolvers\FakerResolver::class,
                'definitions' => [
                    \app\models\MyModel::class => function (\Faker\Generator $faker) {
                        return [
                            'id' => $faker->numberBetween(1, 100),
                            'username' => $faker->userName,
                            'password' => $faker->password
                        ];
                    }
                ]
            ]
        ]
    ],
    ```
2. Now you can do:

```
Yii::$app->factory->setModel(\app\models\MyModel::class)->make();
```

### Function in base TestCase

[](#function-in-base-testcase)

In your base TestCase class you can create simple function:

```
/**
 * Create model factory
 *
 * @param string $model
 * @param int $amount
 * @return \dmirogin\fakemodel\ModelFactory
 */
protected function factory(string $model, int $amount = 1): \dmirogin\fakemodel\ModelFactory
{
    /** @var \dmirogin\fakemodel\ModelFactory $factory */
    $factory = Yii::$app->factory;
    return $factory->setModel($model)->setAmount($amount);
}
```

and call just by:

```
$this->factory(\app\models\MyModel::class)->make();
```

### Enhanced example

[](#enhanced-example)

```
'factory' => [
    'class' => \dmirogin\fakemodel\ModelFactory::class,
    'resolvers' => [
        [
            'class' => \dmirogin\fakemodel\resolvers\FakerResolver::class,
            'definitions' => [
                \app\models\MyModel::class => function (\Faker\Generator $faker) {
                    return [
                        'id' => $faker->numberBetween(1, 100),
                        'username' => $faker->userName,
                        'password' => $faker->password
                    ];
                }
            ]
        ],
        [
            'class' => \dmirogin\fakemodel\resolvers\StatesResolver::class,
            'definitions' => [
                \app\models\MyModel::class => [
                    'admin' => [
                        'id' => 1
                    ]
                ]
            ]
        ]
    ]
],

Yii::$app->factory->setModel(\app\models\MyModel::class)->states(['admin'])->setAmount(5)->make();
```

See more in [WIKI](https://github.com/dmirogin/fakemodel/wiki).

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 84.4% 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

Unknown

Total

1

Last Release

3117d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5470439?v=4)[Dmitry Dorogin](/maintainers/dmirogin)[@dmirogin](https://github.com/dmirogin)

---

Top Contributors

[![dmirogin](https://avatars.githubusercontent.com/u/5470439?v=4)](https://github.com/dmirogin "dmirogin (27 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![askobara](https://avatars.githubusercontent.com/u/7037948?v=4)](https://github.com/askobara "askobara (1 commits)")[![cebe](https://avatars.githubusercontent.com/u/189796?v=4)](https://github.com/cebe "cebe (1 commits)")[![cybernic](https://avatars.githubusercontent.com/u/5999069?v=4)](https://github.com/cybernic "cybernic (1 commits)")

---

Tags

factoryfixturesyii2-extensiontestsyii2

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dmirogin-fakemodel/health.svg)

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

###  Alternatives

[craftcms/cms

Craft CMS

3.6k3.6M2.9k](/packages/craftcms-cms)[yii2-extensions/phpstan

PHPStan extension for Yii2

19152.4k26](/packages/yii2-extensions-phpstan)

PHPackages © 2026

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