davidbadura/faker-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Installs: 66 985

Dependents: 1

Suggesters: 1

Security: 0

Stars: 12

Watchers: 2

Forks: 2

Open Issues: 2

Type:symfony-bundle

1.1.0 2015-09-14 08:59 UTC

This package is auto-updated.

Last update: 2022-07-26 10:02:39 UTC


README

The project is no longer supported.

Build Status Bitdeli Badge

This bundle provide the fzaninotto/Faker, a PHP library that generates fake data for you. You can use this bundle in combination with DavidBaduraFixturesBundle.

Usage

$faker = $container->get('davidbadura_faker.faker');
  // generate data by accessing properties
echo $faker->name;
  // 'Lucy Cechtelar';
echo $faker->address;
  // "426 Jordy Lodge
  // Cartwrightshire, SC 88120-6700"
echo $faker->text;
  // Sint velit eveniet. Rerum atque repellat voluptatem quia rerum. Numquam excepturi
  // beatae sint laudantium consequatur. Magni occaecati itaque sint et sit tempore. Nesciunt
  // amet quidem. Iusto deleniti cum autem ad quia aperiam.
  // A consectetur quos aliquam. In iste aliquid et aut similique suscipit. Consequatur qui
  // quaerat iste minus hic expedita. Consequuntur error magni et laboriosam. Aut aspernatur
  // voluptatem sit aliquam. Dolores voluptatum est.
  // Aut molestias et maxime. Fugit autem facilis quos vero. Eius quibusdam possimus est.
  // Ea quaerat et quisquam. Deleniti sunt quam. Adipisci consequatur id in occaecati.
  // Et sint et. Ut ducimus quod nemo ab voluptatum.

For more information, you can read the faker library documentation.

Installation

Add DavidBaduraFakerBundle in your composer.json

{
    "require": {
        "davidbadura/faker-bundle": "1.0.*"
    }
}

and modify your AppKernel

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
    $bundles[] = new DavidBadura\FakerBundle\DavidBaduraFakerBundle();
}

Bundle configuration

# app/config/config.yml
david_badura_faker:
  locale: de_DE #default: en_EN

Add your own Provider

First, you must create your provider

<?php

namespace YourBundle\Faker\Provider;

class Book extends \Faker\Provider\Base
{
  public function title($nbWords = 5)
  {
    $sentence = $this->generator->sentence($nbWords);
    return substr($sentence, 0, strlen($sentence) - 1);
  }

  public function ISBN()
  {
    return $this->generator->randomNumber(13);
  }
}

now you can register your provider as a service and add the davidbadura_faker.provider tag.

your_bundle.faker.provider.test:
        class: YourBundle\Faker\Provider\Book
        arguments:
            - @davidbadura_faker.faker
        tags:
            -  { name: davidbadura_faker.provider }

finaly, you can use your new provider

$faker = $container->get('davidbadura_faker.faker');
  // generate data by accessing properties
echo $faker->ISBN;
  // '1463738531452';

For more information about providers, you can read the faker library documentation.