heri/faker

Use Faker library to populate your RBSChange 4 database with fake data

Installs: 13

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 3

Forks: 0

Open Issues: 0

Type:rbschange-module

dev-master 2014-03-11 20:31 UTC

This package is not auto-updated.

Last update: 2024-04-13 13:04:24 UTC


README

Have a RBSChange 4 project and need to fill your database for tests?

This module provides a command to load random data for any documents like media, products or orders for instance. It integrates Faker, a PHP library that generates fake data.

Installation

Add the requirement to your composer.json file:

{
    "require": {
        "heri/faker": "dev-master"
    }
}

Then, install the module in the modules manager.

Usage

How it's works?

Specify entities to load, and the number of documents you want to create, in your configuration file project.json:

{
    "Heri":{
        "Faker":{
            "entities":{
                "Rbs_Media_Image":{
                    "number": 5
                },
                "Rbs_Brand_Brand":{
                    "number": 5
                },
                "Rbs_Stock_Sku":{
                    "number": 5
                },
                "Rbs_Catalog_Product":{
                    "number": 5
                }
            }
        }
    }
}

Lastly, run this command:

    php bin/change.phar faker:populate

In the previous example, the Image and Brand models share a relationship. If Image documents are populated first, Faker is smart enough to relate the populated Brand documents to one of the populated Image documents.

ProTips Configuration

You can add your own formatter for each column of each entity, with or without arguments:

{
    "Rbs_Media_Image":{
        "number": 10,
        "custom_formatters":{
            "path":{
                "method": "storeImage",
                "parameters":{
                    "width": "320",
                    "height": "240",
                    "category": "cats"
                }
            }
        }
    }
}

With the example above, we choose to generate images of cats:

ScreenShot

You can use all formatters provided by Faker:

{
    "Rbs_Stock_Sku":{
        "custom_formatters":{
            "ean13":{
                "method": "randomElement",
                "parameters":{
                    "values": [
                        "1234567891234",
                        "1234567891235",
                        "1234567891236"
                    ]
                }
            }
        }
    }
}

You can also set null to a column value in order to get the default value generated by the orm:

{
    "Rbs_Brand_Brand":{
        "custom_formatters":{
            "title": null
        }
    }
}

License

This module is released under the MIT license. See the complete license in the module:

[Resources/meta/LICENSE](https://raw.github.com/heristop/RbsModuleFaker/master/Resources/meta/LICENSE)