/** * {@inheritdoc} */ public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null) { $this->familiesFile = $outputDir . '/' . self::FAMILIES_FILENAME; $this->delimiter = $config['delimiter']; $count = (int) $config['count']; $attributesCount = (int) $config['attributes_count'] - 1; $requirementsCount = (int) $config['requirements_count'] - 1; $this->identifierAttribute = $config['identifier_attribute']; $this->labelAttribute = $config['label_attribute']; $this->faker = Faker\Factory::create(); $families = []; for ($i = 0; $i < $count; $i++) { $family = []; $family['code'] = self::FAMILY_CODE_PREFIX . $i; foreach ($this->getLocalizedRandomLabels() as $localeCode => $label) { $family['label-' . $localeCode] = $label; } $family['attribute_as_label'] = $this->labelAttribute; $attributes = $this->faker->randomElements($this->getAttributeCodes(), $attributesCount); $attributes = array_unique(array_merge([$this->identifierAttribute, $this->labelAttribute], $attributes)); $family['attributes'] = implode(static::ATTRIBUTE_DELIMITER, $attributes); $requirements = []; foreach ($this->getChannels() as $channel) { $attributeReqs = $this->faker->randomElements($this->getAttributeCodes(), $requirementsCount); $attributeReqs = array_merge([$this->identifierAttribute], $attributeReqs); $family['requirements-' . $channel->getCode()] = implode(static::ATTRIBUTE_DELIMITER, $attributeReqs); } $families[$family['code']] = $family; $progress->advance(); } $this->families = $families; $headers = $this->getAllKeys($this->families); $this->writeCsvFile($this->families, $headers); return $this; }
/** * Returns a random active job * * @return mixed */ protected function getRandomJob($department = null) { $jobs = \App\Models\JobCard::active()->lists('job_cards_id')->toArray(); if ($department == 'printing') { $jobs = \App\Models\JobCard::active()->printingCurrentTen()->lists('job_cards_id')->toArray(); } $randomJob = \App\Models\JobCard::find($this->fake->randomElements($jobs))[0]; return $randomJob; }
/** * Run the database seeds. * * @return void */ public function run() { $users = $this->userRepository->findAll(); $tags = Tag::get(['id'])->pluck('id')->toArray(); for ($i = 0; $i < 20; $i++) { $user = $users->random(); $count = mt_rand(1, 2); $post = Post::instantiate($user, ['title' => $user->name . '的好贴'], $this->faker->randomElements($tags, $count)); Comment::instantiate($user, $post, ['body' => $this->faker->text, 'views' => $this->faker->numberBetween(0, 1000)]); } Post::inRandomOrder()->first()->makeSticky(); }
public function generate($databaseName, $size, $batchSize = 1000) { $this->getConnection()->query(sprintf('USE %s', $databaseName)); $this->reset(); $scopes = array_keys($this->scopeFaker); $numberOfScopes = count($scopes); $currentBatch = 0; $createdRecords = 0; while ($size > $createdRecords) { if ($currentBatch >= $batchSize) { $this->flush(); $currentBatch = 0; } $createdRecords++; $currentBatch++; $code = $this->faker->uuid; $this->batch['entity'][$code] = ['code' => $code]; $this->generateAttributes($this->faker, $this->attribute->getAll(), $code, 0); if ($this->faker->boolean(66)) { $currentScopes = $this->faker->randomElements($scopes, $this->faker->numberBetween(1, $numberOfScopes)); foreach ($currentScopes as $scopeCode) { $this->generateAttributes($this->scopeFaker[$scopeCode], $this->attribute->getAllScopeAware(), $code, $this->scope->getId($scopeCode)); } } } if ($currentBatch > 0) { $this->flush(); } return $this; }
public function test(TestCase $test, Generator $faker) { $values = array_filter(array_keys($this->items), function ($value) { return !!$value; }); if (count($values)) { $test->select($faker->randomElements($values), "{$this->name}"); } return true; }
/** * @param ProductInterface $owner * * @return string[] */ private function getAssociatedProductsAsArray(ProductInterface $owner) { $products = $this->productRepository->findBy(['mainTaxon' => $owner->getMainTaxon()]); $products = $this->faker->randomElements($products, 3); $associatedProducts = []; /** @var ProductInterface $product */ foreach ($products as $product) { $associatedProducts[] = $product->getCode(); } return $associatedProducts; }
/** * @param int $count * @param Video[] $videos * @param User[] $users * @param PathsRepository $paths */ private function createPaths($count, array $videos, array $users, PathsRepository $paths) { $this->out->writeln(Path::class); /** @var ProgressHelper $progress */ $progress = $this->getHelperSet()->get('progress'); $progress->start($this->out, $count); for ($i = 0; $i < $count; ++$i) { $path = new Path(); $path->author = $this->faker->randomElement($users); $path->setList($this->faker->randomElements($videos, 7)); $progress->advance(); $paths->attach($path); } $progress->finish(); }
/** * Get random categories * * @param int $count * * @return array */ protected function getRandomCategoryCodes($count) { return $this->faker->randomElements($this->getCategoryCodes(), $count); }
private function getRandomActiveJob() { $this->jobs = App\Models\JobCard::active()->lists('job_cards_id')->toArray(); return App\Models\JobCard::find($this->fake->randomElements($this->jobs))[0]; }
/** * Provide media specific properties * * @return array */ protected function getMediaProperties() { return ['allowed_extensions' => implode(',', $this->faker->randomElements(['png', 'jpg', 'pdf'], 2))]; }
/** * Get a random attribute from the family * * @param Family $family *,@param int $count * * @return array */ protected function getRandomAttributesFromFamily(Family $family, $count) { return $this->faker->randomElements($this->getAttributesFromFamily($family), $count); }