PHPackages                             wieni/wmmodel\_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. wieni/wmmodel\_factory

AbandonedArchivedDrupal-module[Utility &amp; Helpers](/categories/utility)

wieni/wmmodel\_factory
======================

Define factories that allow you to generate entities with certain fields, filled with random data

2.0.1(2y ago)05.5k11MITPHPPHP ^7.3 || ^8.0

Since May 5Pushed 2y ago7 watchersCompare

[ Source](https://github.com/wieni/wmmodel_factory)[ Packagist](https://packagist.org/packages/wieni/wmmodel_factory)[ RSS](/packages/wieni-wmmodel-factory/feed)WikiDiscussions release/v1 Synced 1mo ago

READMEChangelogDependencies (4)Versions (9)Used By (1)

wmmodel\_factory
================

[](#wmmodel_factory)

[![Latest Stable Version](https://camo.githubusercontent.com/c8d9286991b4061a7b2e3c9ce0d313ef75545b418617981df386eefaf9e2d700/68747470733a2f2f706f7365722e707567782e6f72672f7769656e692f776d6d6f64656c5f666163746f72792f762f737461626c65)](https://packagist.org/packages/wieni/wmmodel_factory)[![Total Downloads](https://camo.githubusercontent.com/8db502c9a826d2cc1692d24c0fcafa553467012301160b67e3bae39b369e5ae5/68747470733a2f2f706f7365722e707567782e6f72672f7769656e692f776d6d6f64656c5f666163746f72792f646f776e6c6f616473)](https://packagist.org/packages/wieni/wmmodel_factory)[![License](https://camo.githubusercontent.com/3860f5169f7cf04e74807a06e2590ef97c90ce2ad7f7aa036c146062d20205a1/68747470733a2f2f706f7365722e707567782e6f72672f7769656e692f776d6d6f64656c5f666163746f72792f6c6963656e7365)](https://packagist.org/packages/wieni/wmmodel_factory)

> Define factories that allow you to generate entities with certain fields, filled with random data

Why?
----

[](#why)

- The built-in way to generate random entities, `ContentEntityStorageInterface::createWithSampleValues`, is lacking in a lot of ways: it is untested, has a lot of issues and is not very flexible.
- Use the same API as [Laravel's model factories](https://laravel.com/docs/master/database-testing#writing-factories)
- Generate realistic content tailored to the entity type using the [Faker](https://github.com/fzaninotto/Faker) library.

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

[](#installation)

This package requires PHP 7.1 and Drupal 8 or higher. It can be installed using Composer:

```
 composer require wieni/wmmodel_factory
```

How does it work?
-----------------

[](#how-does-it-work)

### Creating factories

[](#creating-factories)

Factories are the classes responsible for generating the data that will be used to fill the fields of the newly created entity.

Factories for certain entity type / bundle combinations can be added by creating plugins with the `@EntityFactory` annotation, defining the entity type ID in the `entity_type` parameter and the bundle in the `bundle`parameter. The class should also implement the `EntityFactoryInterface`interface.

It's also possible to create multiple factories for the same entity type / bundle combination by giving them unique names through the `name`annotation parameter.

#### Example

[](#example)

```
