# Faker
Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
Faker is heavily inspired by Perl's [Data::Faker](http://search.cpan.org/~jasonk/Data-Faker-0.07/), and by ruby's [Faker](http://faker.rubyforge.org/).
Faker requires PHP >= 5.3.
## Basic Usage
Use `Faker\Factory::create()` to create and initialize a faker generator, which can generate data by accessing properties named after the type of data you want.
```php
name;
// 'Lucy Cechtelar';
echo $faker->address;
// "426 Jordy Lodge
// Cartwrightshire, SC 88120-6700"
echo $faker->lorem;
// 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.
```
Even if this example shows a property access, each call to `$faker->name` yields a different (random) result. This is because Faker uses `__get()` magic, and forwards `Faker\Generator->$property` calls to `Faker\Generator->format($property)`.
```php
name, "\n";
}
// Adaline Reichel
// Dr. Santa Prosacco DVM
// Noemy Vandervort V
// Lexi O'Conner
// Gracie Weber
// Roscoe Johns
// Emmett Lebsack
// Keegan Thiel
// Wellington Koelpin II
// Ms. Karley Kiehn V
```
## Formatters
Each of the generator properties (like `name`, `address`, and `lorem`) are called "formatters". A faker generator has many of them, packaged in "providers". Here is a list of the bundled formatters in the default locale.
### `Faker\Provider\DateTime`
amPm() // 'am'
century() // 'V'
date() // '2008-11-27'
dateTime() // 2005-08-16 20:39:21
dateTimeBetween() // 1999-02-02 11:42:52
dateTimeThisCentury() // 1964-04-04 11:02:02
dateTimeThisDecade() // 2010-03-10 05:18:58
dateTimeThisMonth() // 2011-10-05 12:51:46
dateTimeThisYear() // 2011-09-19 09:24:37
dayOfMonth() // '29'
dayOfWeek() // 'Thursday'
iso8601() // '2003-10-21T16:05:52+0000'
month() // '06'
monthName() // 'November'
time() // '15:02:34'
unixTime() // 1061306726
year() // '1991'
### `Faker\Provider\Internet`
domainName() // 'mueller.info'
domainWord() // 'von'
email() // 'cshields@rosenbaum.com'
freeEmail() // 'dayna55@gmail.com'
freeEmailDomain() // 'yahoo.com'
ipv4() // '237.149.115.38'
ipv6() // '35cd:186d:3e23:2986:ef9f:5b41:42a4:e6f1'
safeEmail() // 'nbatz@example.org'
tld() // 'info'
url() // 'http://www.runolfsdottir.com/'
userName() // 'tremblay.haylie'
### `Faker\Provider\Lorem`
lorem() // 'Fuga totam reiciendis qui architecto fugiat. (...)'
paragraph() // 'Sed a nam et sint autem. Aut officia aut. Blanditiis et ducimus.'
paragraphs() // array('Amet et est. (...)', 'Sequi cum culpa rem. Rerum exercitationem est.')
sentence() // 'Sit vitae voluptas sint non.'
sentences() // array('Ut optio quos qui illo error nihil.', 'Vero a officia id corporis incidunt.', 'Provident esse hic eligendi quos culpa ut.')
word() // 'aut'
words() // array('porro', 'sed', 'magni')
### `Faker\Provider\en_US\Address`
address() // '8888 Cummings Vista Apt. 101, Susanbury, NY 95473'
buildingNumber() // '484'
city() // 'West Judge'
cityPrefix() // 'Lake'
citySuffix() // 'borough'
country() // 'Falkland Islands (Malvinas)'
postcode() // '17916'
secondaryAddress() // 'Suite 961'
state() // 'NewMexico'
stateAbbr() // 'OH'
streetAddress() // '439 Karley Loaf Suite 897'
streetName() // 'Keegan Trail'
streetSuffix() // 'Keys'
### `Faker\Provider\en_US\Company`
bs() // 'e-enable robust architectures'
catchPhrase() // 'Monitored regional contingency'
company() // 'Bogan-Treutel'
companySuffix() // 'and Sons'
### `Faker\Provider\en_US\Name`
firstName() // 'Maynard'
lastName() // 'Zulauf'
name() // 'Dr. Zane Stroman'
prefix() // 'Ms.'
suffix() // 'Jr.'
### `Faker\Provider\en_US\PhoneNumber`
phoneNumber() // '132-149-0269x3767'
## Localization
`Faker\Factory` can take a locale as an argument, to return localized data. If no localized provider is found, the factory fallbacks to the default locale.
```php
name; // 'Jean Dupont'
```
## Seeding the Generator
You may want to get always the same generated data - for instance when using Faker for unit testing purposes. The generator offers a `seed()` method, which seeds the random number generator. Calling the same script twice with the same seed produces the same results.
```php
seed(1234);
echo $faker->name; // 'Jess Mraz I';
```
## Faker Internals: Understanding Providers
A `Faker\Generator` alone can't do much generation. It needs `Faker\Provider` objects to delegate the data generation to them. `Faker\Factory::create()` actually creates a `Faker\Generator` bundled with the default providers. Here is what happens under the hood:
```php
addProvider(new Faker\Provider\en_US\Name($faker));
$faker->addProvider(new Faker\Provider\en_US\Address($faker));
$faker->addProvider(new Faker\Provider\en_US\PhoneNumber($faker));
$faker->addProvider(new Faker\Provider\en_US\Company($faker));
$faker->addProvider(new Faker\Provider\Lorem($faker));
$faker->addProvider(new Faker\Provider\Internet($faker));
````
Whenever you try to access a property on the `$faker` object, the generator looks for a method with the same name in all the providers attached to it. For instance, calling `$faker->name` triggers a call to `Faker\Provider\Name::name()`.
That means that you can esily add your own providers to a `Faker\Generator`. Just have a look at the existing providers to see how you can design powerful data generators in no time.
## Real Life Usage
The following script generates a valid XML document:
```php
address ?>
streetAddress ?>
city ?>
postcode ?>
state ?>
bs ?>
lorem(3) ?>
]]>
```
Running this script produces a document looking like:
```xml
39640 Alize Radial
North Robbburgh
06688-4406
Colorado
e-enable bleeding-edge interfaces
973 Bruen Lock Suite 302
Konopelskimouth
11578-6604
Nebraska
1715 King Island Suite 086
Schmittside
03005-2057
Colorado
455 Mitchell Harbor Suite 177
South Alfordville
09848-8284
Idaho
5024 Kulas Cliffs
West Carter
24046
SouthCarolina
4313 Edmond Lights
North Elenahaven
40625
Maryland
6277 Bruen Pass
New Emeliaport
55131-3794
Arkansas
9900 Wellington Center
Irvingbury
58271
Nevada
07633 Ryann Throughway
Hicklefurt
97260
WestVirginia
53265 Abernathy Lock
South Rosettastad
85744
Oklahoma
```
## License
Faker is released under the MIT Licence.
Copyright (c) 2011 François Zaninotto
Portions Copyright (c) 2008 Caius Durling
Portions Copyright (c) 2008 Adam Royle
Portions Copyright (c) 2008 Fiona Burrows
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.