Say Goodbye to Fixture Files: Introducing Faker

Say Goodbye to Fixture Files: Introducing FakerDuring the early phases of development, a website needs fake data to test the model, the look and feel, the backend administration. Writing this test data is often a hassle. You need to imagine names, emails, titles, content for dozens - if not thousands - of records.

Modern web frameworks provide simple shorcuts to minimize that hassle (via fixture files for instance), but you still have to write the test data somewhere. The workload is proportional to the amount of data you need to insert.

How can you avoid that workload? By generating the test data. After all, generating a phone number, a date of birth, a name isn't difficult. You've probably already done that a couple times. But did you ever package this data generation logic into a reusable library?

I did. It's called Faker.

Faker is a standalone library that lets you generate all kind of data, from emails to articles, in a simple way. It's extensible, it supports localization, and it's open-source (MIT licence). Heavily inspired by Data::Faker and ruby's faker, Faker is a PHP library that will find a place of choice in your stack of web development tools.

Usage is super-simple:

With that, not only can you generate fixture files for Database insertion, but you can also direcly populate a database using an ORM, in PHP. Or create test XML files (see the example in the Faker documentation).

And it's not only for the early stages of development, either. Don't you ever need to grab the data from a production environment to put it to the development environment? In those case, don't you need to anonymize user data? Faker can help there, too.

Grab it while it's hot, add your own data providers or localization, and don't forget to give me your feedback. 

Published on 17 Oct 2011 with tags development open source php

comments powered by Disqus