Giter Club home page Giter Club 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.

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 (Symfony 2):

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

Register the namespace in app/autoload.php (Symfony 2.1):

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

Register the bundle in app/AppKernel.php:

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

Reference Configuration

In order to use the BazingaFakerBundle, you have to configure it.

First of all if you use Doctrine or Mandango instead of Propel you must define it so that the bundle can reconfigure itself:

# app/config/config*.yml

bazinga_faker:
    orm: doctrine
# app/config/config*.yml

bazinga_faker:
    orm: mandango

Afterwards you just need to configure which entities you want to populate and in which quantity (default: 5).

# app/config/config*.yml

bazinga_faker:
    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:

bazinga_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:

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

You can also set null to a column value in order to get the default value generated by a behavior (e.g. Propel behaviors):

bazinga_faker:
    entities:
        Acme\LibraryBundle\Model\Book:
            custom_formatters:
                Slug:   { method: null }

There are a few more optional settings available for more advanced customization of faker:

bazinga_faker:
    seed:       1234
    locale:     en_GB
    populator:  Your\Own\Populator
    entity:     Your\Own\EntityPopulator

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 mamartins avatar havvg avatar pablodip avatar gelolabs avatar seldaek avatar dafish avatar

Watchers

James Cloos 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.