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

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


Split.js is a lightweight, unopinionated utility for creating adjustable split views or panes.



Apipie- Rails DSL and API documentation lib. Allows to specify validation, versioning etc.



Segment - a little JavaScript class (without dependencies) to draw and animate SVG path strokes.



PgBarman - PostgreSQL backup tool. Hot backups, point in time recovery and many other features.