/** * @return Generator */ private function faker() { if (null === $this->faker) { $this->faker = Factory::create('en_US'); $this->faker->seed(9000); } return $this->faker; }
/** * Creates the application. * * @return \Illuminate\Foundation\Application */ public function createApplication() { $app = (require __DIR__ . '/../bootstrap/app.php'); $app->make('Illuminate\\Contracts\\Console\\Kernel')->bootstrap(); $this->faker = \Faker\Factory::create(); $this->faker->seed(1); return $app; }
/** * Specter constructor. * * Initialize with a seed for repeatable fixture data * * @param integer $seed Faker seed value * * @return Specter */ public function __construct($seed = 0) { $this->faker = Faker\Factory::create(); $this->faker->addProvider(new Avatar($this->faker)); $this->faker->addProvider(new RelatedElement($this->faker, $this->trigger)); if ($seed) { $this->faker->seed($seed); } }
public function testIdNumber() { $faker = new Generator(); $faker->addProvider(new Person($faker)); $faker->seed(2); $this->assertRegExp('/^[А-Я]{2}\\d{8}$/u', $faker->idNumber); }
public function setUp() { $faker = new Generator(); $faker->addProvider(new Barcode($faker)); $faker->seed(0); $this->faker = $faker; }
/** * @expectedException \InvalidArgumentException */ public function testTextMinLength() { $generator = new Generator(); $generator->addProvider(new Text($generator)); $generator->seed(0); $generator->realText(9); }
public function testUuidExpectedSeed() { $faker = new Generator(); $faker->seed(123); $this->assertEquals("8e2e0c84-50dd-367c-9e66-f3ab455c78d6", BaseProvider::uuid()); $this->assertEquals("073eb60a-902c-30ab-93d0-a94db371f6c8", BaseProvider::uuid()); }
public function setUp() { $faker = new Generator(); $faker->seed(1); $faker->addProvider(new Person($faker)); $this->faker = $faker; }
public function testLastKanaNameReturnsNagisa() { $faker = new Generator(); $faker->addProvider(new Person($faker)); $faker->seed(1); $this->assertEquals('ナギサ', $faker->lastKanaName); }
/** * Get the Faker generator with the (optionally) configured locale * * @return Generator */ protected function _getFaker() { $locale = $this->getLocale(); $seed = $this->getSeedingNumber(); $this->out(__('Create Faker instance with "%s" locale...', $locale), 1, Shell::VERBOSE); $this->faker = Factory::create($locale); if (!empty($seed)) { $this->out(__("Use seed '%s' for Faker.", $seed), 1, Shell::VERBOSE); $this->faker->seed($seed); } return $this->faker; }
static function factory() { $faker = new Generator(); $faker->addProvider(new \Faker\Provider\zh_CN\Person($faker)); $faker->addProvider(new \Faker\Provider\zh_CN\Address($faker)); $faker->addProvider(new \Faker\Provider\zh_CN\PhoneNumber($faker)); $faker->addProvider(new \Faker\Provider\zh_CN\Company($faker)); $faker->addProvider(new \Faker\Provider\Lorem($faker)); $faker->addProvider(new \Faker\Provider\DateTime($faker)); $faker->addProvider(new \Faker\Provider\Internet($faker)); $faker->addProvider(new \Faker\Provider\Image($faker)); $faker->seed(rand(0, 65535)); return $faker; }
/** * {@inheritDoc} */ public function load(ObjectManager $manager) { $faker = new Generator(); $faker->addProvider(new Person($faker)); $faker->addProvider(new Internet($faker)); $faker->addProvider(new PhoneNumber($faker)); $faker->addProvider(new Lorem($faker)); // Generate default admin $admin = new User(); $admin->setPlainPassword('123456'); $admin->setEmail('*****@*****.**'); $admin->setEnabled(true); $admin->setType(User::ROLE_ADMIN); $admin->setFirstName($faker->firstName); $admin->setLastName($faker->lastName); $manager->persist($admin); // Generate default student $student = new User(); $student->setPlainPassword('123456'); $student->setEmail('*****@*****.**'); $student->setEnabled(true); $student->setType(User::ROLE_STUDENT); $student->setStudentProfileVisibility(User::VISIBILITY_VISIBLE); $student->setFirstName($faker->firstName); $student->setLastName($faker->lastName); $faker->seed(rand(1, 10)); $studentProfile = new StudentProfile(); $studentProfile->setContactEmail($student->getEmail()); $studentProfile->setHeadline($faker->sentence); $student->setStudentProfile($studentProfile); $manager->persist($student); // Generate stat for student for ($i = 0; $i < 30; $i++) { $numProfileView = rand(0, 15); $numShortlist = rand(0, round($numProfileView / 2)); for ($y = 0; $y < $numProfileView; $y++) { $time = (new \DateTime('now'))->modify('-' . $i . ' days'); $time->setTime(rand(1, 11), rand(1, 30), 0); $statProfileView = new StatProfileView(); $statProfileView->setCreated($time); $statProfileView->setStudent($studentProfile); $manager->persist($statProfileView); } for ($z = 0; $z < $numShortlist; $z++) { $time = (new \DateTime('now'))->modify('-' . $i . ' days'); $time->setTime(rand(1, 11), rand(1, 30), 0); $statShortlist = new StatShortlist(); $statShortlist->setCreated($time); $statShortlist->setStudent($studentProfile); $manager->persist($statShortlist); } } // Generate default member $member = new User(); $member->setPlainPassword('123456'); $member->setEmail('*****@*****.**'); $member->setEnabled(true); $member->setType(User::ROLE_GS1_MEMBER); $member->setFirstName($faker->firstName); $member->setLastName($faker->lastName); $manager->persist($member); // Generate 20 more accounts of students and members for ($i = 0; $i < 20; $i++) { $faker->seed(rand(($i + 1) * 10, ($i + 2) * 10)); $user = new User(); $user->setPlainPassword('123456'); $user->setEmail($faker->email); $user->setEnabled(true); $user->setFirstName($faker->firstName); $user->setLastName($faker->lastName); $shouldBeAMember = $faker->numberBetween(0, 2) == 0; if ($shouldBeAMember) { $user->setType(User::ROLE_GS1_MEMBER); } else { $user->setType(User::ROLE_STUDENT); // disable few students $shouldEnableStudent = $faker->numberBetween(0, 2) != 0; $user->setStudentProfileVisibility($shouldEnableStudent ? User::VISIBILITY_VISIBLE : User::VISIBILITY_HIDDEN); $studentProfile = new StudentProfile(); $studentProfile->setContactEmail($user->getEmail()); $studentProfile->setHeadline($faker->sentence); $phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance(); try { $studentProfile->setContactNumber($phoneUtil->parse($faker->mobileNumber, "AU")); } catch (\libphonenumber\NumberParseException $e) { } $user->setStudentProfile($studentProfile); } $manager->persist($user); } $manager->flush(); }
public function testSeed() { $generator = new Generator(); $generator->seed(0); $mtRandWithSeedZero = mt_rand(); $generator->seed(0); $this->assertEquals($mtRandWithSeedZero, mt_rand(), 'seed(0) should be deterministic.'); $generator->seed(); $mtRandWithoutSeed = mt_rand(); $this->assertNotEquals($mtRandWithSeedZero, $mtRandWithoutSeed, 'seed() should be different than seed(0)'); $generator->seed(); $this->assertNotEquals($mtRandWithoutSeed, mt_rand(), 'seed() should not be deterministic.'); }
public function testSeed() { $generator = new Generator(); $generator->seed(0); $mtRandWithSeedZero = mt_rand(); $generator->seed(0); $this->assertEquals($mtRandWithSeedZero, mt_rand(), 'seed(0) should be deterministic.'); $generator->seed(); $mtRandWithoutSeed = mt_rand(); $this->assertNotEquals($mtRandWithSeedZero, $mtRandWithoutSeed, 'seed() should be different than seed(0)'); $generator->seed(); $this->assertNotEquals($mtRandWithoutSeed, mt_rand(), 'seed() should not be deterministic.'); $generator->seed('10'); $this->assertTrue(true, 'seeding with a non int value doesn\'t throw an exception'); }