GithubHelp home page GithubHelp logo

bazingafakerbundle's Introduction

FakerBundle

This bundle integrates Faker, a PHP library that generates fake data for you. It provides a command to load random data for your model objects as simple as possible.

Note: It only works out of the box with Propel ORM at the moment but you can configure your own populator so it can works with all database abstraction systems.

Installation

Install this bundle as usual:

git submodule add git://github.com/willdurand/BazingaFakerBundle.git vendor/bundles/Bazinga/Bundle/FakerBundle

Add the Faker library:

git submodule add git://github.com/fzaninotto/Faker.git vendor/faker

Register the namespace in app/autoload.php:

// app/autoload.php
$loader->registerNamespaces(array(
    // ...
    'Bazinga'          => __DIR__.'/../vendor/bundles',
    'Faker'            => __DIR__.'/../vendor/faker/src',
));

Register the bundle in app/AppKernel.php:

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Bazinga\Bundle\FakerBundle\FakerBundle(),
    );
}

Reference Configuration

In order to use the BazingaFakerBundle, you have to configure it. Actually, you just need to configure entities you want to populate and in which quantity (default: 5).

# app/config/config*.yml

faker:
    seed:      1234
    locale:    en_GB 
    populator: \Your\Own\Populator
    entities:
        Acme\LibraryBundle\Model\Author:
            number: 5
        Acme\LibraryBundle\Model\Book:
            number: 5
            custom_formatters:
                Isbn:   { method: lexify, parameters: [ '?????????????' ] }

You can add your own formatter for each column of each entity:

faker:
    entities:
        Acme\LibraryBundle\Model\Book:
            custom_formatters:
                Isbn:   { method: randomElement, parameters: [ 'aaaaaaaaaa', 'bbbbbbbb', 'cccccccc' ] }

You can use all formatters provided by Faker, with or without arguments:

faker:
    entities:
        Acme\LibraryBundle\Model\Book:
            custom_formatters:
                Isbn:   { method: word }

Command

The bundle provides a new Symfony2 command: faker:populate which will populate all configured entities.

php app/console faker:populate

Usage

In real life, you'll have to populate your database with data. It's often a pain because it requires imagination and time you probably don't have or you don't want to waste. Faker to the rescue!

You just have to configure your entities to populate, then run the faker:populate command to add new data without effort. It's better than fixtures because you don't need to write anything. If you drop your database, then re create it and load fresh data.

Credits

  • François Zaninotto (Creator of Faker)
  • William Durand

License

See Resources/meta/LICENSE.

bazingafakerbundle's People

Contributors

willdurand avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.