Faker - generating test data for database > stdout.in Ievgen Kuzminov IT blog

Faker - generating test data for database

Feb 6, 2014, 9:27:23 AM

Faker is a library that provide a set of generators for data types like fake name, address, number, IP, email, lorem ipsum text etc. - all generic data that is needed to create semi-real database content. Usually it has variations for different popular languages. All data is human-readable and taken from library, a lot of different combinations creates semi-unique data set.

It is needed mostly on testing and demonstration stages. Nobody likes to see a list of users like "test1", "Johnny35" etc. with posts "Test1", "Another test 35".

Implementation

PHP usage example

$faker = Faker\Factory::create();

// 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 ...
for ($i=0; $i < 5; $i++) {
  echo $faker->name, "\n";
}
  // Adaline Reichel
  // Dr. Santa Prosacco DVM
  // Noemy Vandervort V
  // Lexi O'Conner
  // Gracie Weber

NB! Yii2 Framework has a Faker fixtures extensions

comments powered by Disqus
Ievgen
Kuzminov "iJackUA"
Web Team Lead
at MobiDev (Kharkiv, Ukraine)
Code in Ruby and Elixir, but still love PHP. Explore ES6 and Vue.js. Explore databases, use Ubuntu and MacOS, think about IT people and management

Notes


Animista - is a place where you can play with a collection of ready to use CSS animations, tweak them and download only those you will actually use.



Staticman - handles user-generated content for you and transforms it into data files that sit in your GitHub repository, along with the rest of your content.