Questions tagged [faker]

An extension or library used in certain programming languages or frameworks (namely Ruby or Yii2) for generating fake data for debug purposes and testing.

In Ruby, Faker, a port of Data::Faker from Perl, is used to easily generate fake data: names, addresses, phone numbers, etc.

In Yii2, Faker can generate random strings (like name, address, phone number or anything), random numbers, keys or harshes as well as long sentences of fake text. It can be accessed in OOP style.

A PHP library is available for Faker that is used in some frameworks such as Laravel.

565 questions
10
votes
4 answers

Rspec controller test failing with Apostrophe Character?

Right now I have unit tests that are failing using the "Faker" Company Name. it seems like the expect(response.body).to match(@thing.name) is whats getting messed up. When looking at the error, the Faker Company names will sometimes have things like…
msmith1114
  • 1,853
  • 3
  • 18
  • 60
10
votes
3 answers

How to seed database in yii2?

I am new to Yii framework. I want to seed my database like it can be done in Laravel framework using Faker. I tried this http://www.yiiframework.com/forum/index.php/topic/59655-how-to-seed-yii2-database/ but it does not provide much details. I would…
Faisal Qureshi
  • 211
  • 2
  • 9
10
votes
1 answer

How to change generated text's language in fzaninotto/Faker?

In Laravel I use Faker. (fzaninotto/Faker) Can't change locale(language) of generated texts. My code: use Faker\Factory as Faker; class MySeeder extends Seeder { public function run() { $faker = Faker::create('ru_RU'); …
YanDatsiuk
  • 1,355
  • 2
  • 15
  • 27
9
votes
1 answer

In Factory Boy, how to join strings created with Faker?

I want to use Factory Boy and its support for Faker to generate strings from more than one provider. e.g. combining prefix and name: # models.py from django.db import models class Person(models.Model): full_name =…
Phil Gyford
  • 10,767
  • 11
  • 51
  • 112
9
votes
3 answers

Should we be using Faker in Rails Factories?

I love Faker, I use it in my seeds.rb all the time to populate my dev environment with real-ish looking data. I've also just started using Factory Girl which also saves a lot of time - but when i sleuth around the web for code examples I don't see…
Huw
  • 595
  • 9
  • 24
9
votes
2 answers

Use Faker gem to generate correlated city, postal code, country code values

Is there a way to get the Faker gem to generate 'correlated' city and country code values? For example, Vancouver, CA Minneapolis, MN I'm doing this: FactoryGirl.define do factory :location do ... city {Faker::Address.city} …
craig
  • 23,835
  • 20
  • 98
  • 183
9
votes
1 answer

How to generate coherent data with Rails Faker gem?

In order to populate my Rails application with fake data I often do this: person = Person.create( :first_name => Faker::Name.first_name, :last_name => Faker::Name.last_name, :email => Faker::Internet.email ) This might produce a…
Tintin81
  • 8,860
  • 17
  • 66
  • 143
8
votes
1 answer

How to use lazy_attribute with Faker in Factory Boy

Context: I have a model with two dates, I want to use factory.Faker for both of them but the second date should always be greater that the first one. I tried this: Model excerpt: class Event(models.Model): execution_start_date =…
diegueus9
  • 20,833
  • 15
  • 58
  • 73
8
votes
4 answers

Generate an array with random data without using a for loop

I am using the faker.js library to generate random data and I have a couple of factory functions that generate a series of user data: const createUser = () => { return { name: faker.name.findName(), email: faker.internet.email(), …
Amit Erandole
  • 10,436
  • 20
  • 60
  • 92
7
votes
3 answers

Using PHP Faker in Laravel to generate "unique with" entry when seeding a database using a factory

So Similar to the unique with validation rule (See: https://github.com/felixkiss/uniquewith-validator), I want to know how to generate a entry, where one column is unique with another one. I want to seed my database as follows. Example: There are 12…
J. Robinson
  • 760
  • 1
  • 12
  • 41
7
votes
2 answers

How to set length for python Faker fields

I am trying to set up UserFactory using DjangoModelFactory from factory_boy and Faker. Here is my code. fake = Faker('uk_UA') class UserFactory(DjangoModelFactory): class Meta: model = User username = fake.user_name first_name…
Myroslav Hryshyn
  • 514
  • 4
  • 16
7
votes
4 answers

Faker generating strange phone numbers?

So I'm creating a database with Laravel and seeding it, and I ran into an issue where it generates a phone number as follows: (635) 889-5802 x45134. This causes issues by exceeding the desired length of the database column. So my questions are: On…
dluxcru
  • 357
  • 1
  • 4
  • 16
7
votes
4 answers

Laravel faker generate gender from name

What is the optimum way of generating gender using faker, having generated a name so that the gender matches the name return [ 'name' => $faker->name, 'email' => $faker->safeEmail, 'username' => $faker->userName, 'phone' =>…
Morris Mukiri
  • 73
  • 1
  • 2
  • 8
7
votes
2 answers

How to generate latitude, longitude info using Faker from Laravel seeder?

I am trying to use Faker in a Laravel seeder. Here is how my seeder class look like
Jaylen
  • 33,621
  • 35
  • 108
  • 193
7
votes
2 answers

Laravel 5.1 foreign keys in model factory

How do you define foreign keys in a model factory. For example if I have a organisations table which has a foreign key to the countries table, in my model factory I'm having to define a dummy value for the country id as…
adam78
  • 8,002
  • 17
  • 68
  • 154
1
2
3
37 38