해외축구중계스포츠중계축구중계EPL중계스포츠무료중계실시간스포츠
{"id":272,"date":"2017-09-30T13:32:15","date_gmt":"2017-09-30T13:32:15","guid":{"rendered":"https:\/\/www.wdb24.com\/?p=272"},"modified":"2018-04-22T20:44:01","modified_gmt":"2018-04-22T20:44:01","slug":"use-faker-php-library-that-generates-fake-data","status":"publish","type":"post","link":"https:\/\/www.wdb24.com\/use-faker-php-library-that-generates-fake-data\/","title":{"rendered":"How to use Faker \u2013 PHP library that generates fake data"},"content":{"rendered":"

\"how<\/a>
\nAs a developer almost every project that I am working needs some dummy data. Because without data I cannot test my application in which I am working. In the old days of my programming I usually create a form and insert dummy data. To be very honest I hate that process because data insertion took lot of time.<\/p>\n

But now lots of PHP<\/a> libraries are available to tackle this problem. Faker<\/a> is one of them. Faker is a fake data library inspired by PERL\u2019s Data::Faker and by RUBY\u2019s Faker. As per official definition. <\/p>\n

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.<\/p><\/blockquote>\n

Faker Installation:<\/h2>\n

There are 3 ways to download Faker. Composer, GIT and direct download .In this tutorial I am going to download Faker via GIT. <\/p>\n

GIT Link:<\/h4>\n

https:\/\/github.com\/fzaninotto\/Faker.git<\/code><\/p>\n

Direct Download Link:<\/h4>\n

https:\/\/github.com\/fzaninotto\/Faker\/archive\/master.zip<\/code><\/p>\n

Composer Command:<\/h4>\n

composer require fzaninotto\/faker<\/code><\/p>\n

After downloading Faker via GIT its directory structure will look like this.<\/p>\n

\"faker<\/a><\/p>\n

For now there are 2 important folders, one is src<\/strong> and second is test<\/strong>. SRC folder has all the source of Faker Library. And in the test folder you can see its documentation and test file. I am going to work on test directory. Now I am going to create a file as hello-world.php<\/strong> and include faker autoload file and create its instance.<\/p>\n

Also visit Insert dummy data into MYSQL using PHP<\/a><\/p><\/blockquote>\n

Usage:<\/h3>\n

Hello-world.php:<\/h4>\n
\r\nname;\r\necho  \u201c
\u201d;\r\necho $faker->address;\r\necho \u201c
\u201d;\r\necho $faker->text;\t\r\n?>\r\n\r\n<\/pre>\n

I created $faker<\/code> as an instance. Factory::create()<\/code> can take a locale as an argument and returned localized data but by default it takes en_US. You can check available Faker locale in the src\\Faker\\Provider<\/strong> directory. $faker->name<\/code> returns different name so as $faker->address<\/code> and $faker->text<\/code> .<\/p>\n

\n<\/ins>
\n