public function setUp() { $this->faker = Factory::create(); $this->id = TwitterMessageId::create($this->faker->uuid); $this->lang = $this->faker->countryISOAlpha3; $this->userName = $this->faker->userName; $this->hashtagText = $this->faker->word; $this->text = $this->faker->text(); $this->complexText = '@' . $this->userName . ' ' . $this->text . ' #' . $this->hashtagText; $this->date = new \DateTimeImmutable(); $this->coordinates = \Mockery::mock(TwitterCoordinates::class); $this->place = \Mockery::mock(TwitterPlace::class); $this->inReplyToStatusId = $this->faker->randomNumber(); $this->inReplyToUserId = $this->faker->randomNumber(); $this->inReplyToScreenName = $this->faker->userName; $this->retweeted = $this->faker->boolean(); $this->retweetCount = $this->faker->randomNumber(); $this->favorited = $this->faker->boolean(); $this->favoriteCount = $this->faker->randomNumber(); $this->truncated = $this->faker->boolean(); $this->source = null; $this->retweetedStatus = \Mockery::mock(Tweet::class); $this->hashtag = \Mockery::mock(TwitterHashtag::class); $this->userMention = \Mockery::mock(TwitterUserMention::class); $this->sender = \Mockery::mock(TwitterUser::class); $this->recipient = \Mockery::mock(TwitterUser::class); $this->entities = \Mockery::mock(TwitterEntities::class); }
/** * @param FactoryInterface $userFactory */ public function __construct(FactoryInterface $userFactory) { $this->userFactory = $userFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('email', function (Options $options) { return $this->faker->email; })->setDefault('username', function (Options $options) { return $this->faker->firstName . ' ' . $this->faker->lastName; })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('password', 'password123')->setDefault('api', false); }
/** * @param FactoryInterface $taxRateFactory * @param RepositoryInterface $zoneRepository * @param RepositoryInterface $taxCategoryRepository */ public function __construct(FactoryInterface $taxRateFactory, RepositoryInterface $zoneRepository, RepositoryInterface $taxCategoryRepository) { $this->taxRateFactory = $taxRateFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('amount', function (Options $options) { return $this->faker->randomFloat(2, 0, 1); })->setAllowedTypes('amount', 'float')->setDefault('included_in_price', function (Options $options) { return $this->faker->boolean(); })->setAllowedTypes('included_in_price', 'bool')->setDefault('calculator', 'default')->setDefault('zone', LazyOption::randomOne($zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($zoneRepository, 'code'))->setDefault('tax_category', LazyOption::randomOne($taxCategoryRepository))->setAllowedTypes('tax_category', ['null', 'string', TaxCategoryInterface::class])->setNormalizer('tax_category', LazyOption::findOneBy($taxCategoryRepository, 'code')); }
/** * Run the database seeds. * * @return void */ public function run() { $shops = $this->shopRepository->findAll(); // assign 3 shipping plans with 3 shipping optinos each to 80% of shops foreach ($shops as $shop) { if ($this->faker->boolean(20)) { continue; } /** @var Shop $shop */ $shop->shippingPlans()->saveMany(factory(ShippingPlan::class, 3)->make())->each(function ($shippingPlan) { /** @var ShippingPlan $shippingPlan */ $shippingPlan->shippingOptions()->saveMany(factory(ShippingOption::class, 3)->make()); }); } // assign shipping plan to each product if owner has any // or 0 if owner doesn't $products = $this->productRepository->with('owner.shippingPlans')->findAll(); foreach ($products as $product) { /** @var Seller $seller */ $seller = $product->seller; if ($seller->shippingPlans->count()) { /** @var Product $product */ $product->shippingPlans()->attach($seller->shippingPlans->random()->id); } } }
/** * @return int */ private function randomWinType() { $normal = $this->faker->boolean(70); if ($normal) { return Game::WINTYPE_NORMAL; } $backgammon = $this->faker->boolean(10); if ($backgammon) { return Game::WINTYPE_BACKGAMMON; } return Game::WINTYPE_GAMMON; }
/** * @param FactoryInterface $paymentMethodFactory * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $paymentMethodFactory, RepositoryInterface $localeRepository) { $this->paymentMethodFactory = $paymentMethodFactory; $this->localeRepository = $localeRepository; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('gateway', 'offline')->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool'); }
/** * @param FactoryInterface $staticContentFactory */ public function __construct(FactoryInterface $staticContentFactory) { $this->staticContentFactory = $staticContentFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('title', function (Options $options) { return $this->faker->words(3, true); })->setDefault('name', function (Options $options) { return StringInflector::nameToCode($options['title']); })->setDefault('body', function (Options $options) { return $this->faker->paragraphs(4, true); })->setDefault('publishable', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('publishable', 'bool'); }
/** * @param FactoryInterface $shippingMethodFactory * @param RepositoryInterface $zoneRepository * @param RepositoryInterface $shippingCategoryRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $shippingMethodFactory, RepositoryInterface $zoneRepository, RepositoryInterface $shippingCategoryRepository, RepositoryInterface $localeRepository) { $this->shippingMethodFactory = $shippingMethodFactory; $this->localeRepository = $localeRepository; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('zone', LazyOption::randomOne($zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($zoneRepository, 'code'))->setDefault('shipping_category', LazyOption::randomOne($shippingCategoryRepository))->setAllowedTypes('shipping_category', ['null', 'string', ShippingCategoryInterface::class])->setNormalizer('shipping_category', LazyOption::findOneBy($shippingCategoryRepository, 'code'))->setDefault('calculator', function (Options $options) { return ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => ['amount' => 4200]]; }); }
/** * Run the database seeds. * * @return void */ public function run() { $shops = $this->shopRepository->findAll(); foreach ($shops as $shop) { if ($this->faker->boolean(80)) { $this->seed($shop); } } $users = $this->userRepository->findAll(); foreach ($users as $user) { if ($this->faker->boolean(80)) { $this->seed($user); } } }
/** * @param OrderInterface $order */ private function completeCheckout(OrderInterface $order) { if ($this->faker->boolean(25)) { $order->setNotes($this->faker->sentence); } $this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_COMPLETE); }
/** * @param ChannelFactoryInterface $channelFactory * @param RepositoryInterface $localeRepository * @param RepositoryInterface $currencyRepository * @param RepositoryInterface $paymentMethodRepository * @param RepositoryInterface $shippingMethodRepository */ public function __construct(ChannelFactoryInterface $channelFactory, RepositoryInterface $localeRepository, RepositoryInterface $currencyRepository, RepositoryInterface $paymentMethodRepository, RepositoryInterface $shippingMethodRepository) { $this->channelFactory = $channelFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('hostname', function (Options $options) { return $options['code'] . '.localhost'; })->setDefault('color', function (Options $options) { return $this->faker->colorName; })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('locales', LazyOption::all($localeRepository))->setAllowedTypes('locales', 'array')->setNormalizer('locales', LazyOption::findBy($localeRepository, 'code'))->setDefault('currencies', LazyOption::all($currencyRepository))->setAllowedTypes('currencies', 'array')->setNormalizer('currencies', LazyOption::findBy($currencyRepository, 'code'))->setDefault('payment_methods', LazyOption::all($paymentMethodRepository))->setAllowedTypes('payment_methods', 'array')->setNormalizer('payment_methods', LazyOption::findBy($paymentMethodRepository, 'code'))->setDefault('shipping_methods', LazyOption::all($shippingMethodRepository))->setAllowedTypes('shipping_methods', 'array')->setNormalizer('shipping_methods', LazyOption::findBy($shippingMethodRepository, 'code')); }
/** * @param FactoryInterface $productFactory * @param FactoryInterface $productVariantFactory * @param ProductVariantGeneratorInterface $variantGenerator * @param FactoryInterface $productAttributeValueFactory * @param FactoryInterface $productImageFactory * @param ImageUploaderInterface $imageUploader * @param SlugGeneratorInterface $slugGenerator * @param RepositoryInterface $taxonRepository * @param RepositoryInterface $productAttributeRepository * @param RepositoryInterface $productOptionRepository * @param RepositoryInterface $channelRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $productFactory, FactoryInterface $productVariantFactory, ProductVariantGeneratorInterface $variantGenerator, FactoryInterface $productAttributeValueFactory, FactoryInterface $productImageFactory, ImageUploaderInterface $imageUploader, SlugGeneratorInterface $slugGenerator, RepositoryInterface $taxonRepository, RepositoryInterface $productAttributeRepository, RepositoryInterface $productOptionRepository, RepositoryInterface $channelRepository, RepositoryInterface $localeRepository) { $this->productFactory = $productFactory; $this->productVariantFactory = $productVariantFactory; $this->variantGenerator = $variantGenerator; $this->productImageFactory = $productImageFactory; $this->imageUploader = $imageUploader; $this->slugGenerator = $slugGenerator; $this->localeRepository = $localeRepository; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('short_description', function (Options $options) { return $this->faker->paragraph; })->setDefault('description', function (Options $options) { return $this->faker->paragraphs(3, true); })->setDefault('main_taxon', LazyOption::randomOne($taxonRepository))->setAllowedTypes('main_taxon', ['null', 'string', TaxonInterface::class])->setNormalizer('main_taxon', LazyOption::findOneBy($taxonRepository, 'code'))->setDefault('taxons', LazyOption::randomOnes($taxonRepository, 3))->setAllowedTypes('taxons', 'array')->setNormalizer('taxons', LazyOption::findBy($taxonRepository, 'code'))->setDefault('channels', LazyOption::randomOnes($channelRepository, 3))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($channelRepository, 'code'))->setDefault('product_attributes', [])->setAllowedTypes('product_attributes', 'array')->setNormalizer('product_attributes', function (Options $options, array $productAttributes) use($productAttributeRepository, $productAttributeValueFactory) { $productAttributesValues = []; foreach ($productAttributes as $code => $value) { /** @var ProductAttributeInterface $productAttribute */ $productAttribute = $productAttributeRepository->findOneBy(['code' => $code]); Assert::notNull($productAttribute); /** @var ProductAttributeValueInterface $productAttributeValue */ $productAttributeValue = $productAttributeValueFactory->createNew(); $productAttributeValue->setAttribute($productAttribute); $productAttributeValue->setValue($value ?: $this->getRandomValueForProductAttribute($productAttribute)); $productAttributesValues[] = $productAttributeValue; } return $productAttributesValues; })->setDefault('product_options', [])->setAllowedTypes('product_options', 'array')->setNormalizer('product_options', LazyOption::findBy($productOptionRepository, 'code'))->setDefault('images', [])->setAllowedTypes('images', 'array'); }
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; }
/** * If we should generate data for a non-required field * * @param bool $required * @return bool */ private function shouldHandle($required) { if (!$required) { $required = $this->generator->boolean($this->config->getChanceRequired()); } return $required; }
/** * Run the database seeds. * * @return void */ public function run() { Role::create(['name' => 'owner']); $users = $this->userRepository->findAll(); foreach ($users as $user) { if ($this->faker->boolean(50)) { $this->seed($user); } } foreach (getTestAccounts() as $testAccount) { /** @var User $testUser */ $testUser = $this->userRepository->findBy('email', $testAccount['email']); if (!$testUser->isShopOwner()) { $this->seed($testUser); } } }
/** * {@inheritdoc} */ public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null) { $this->attributesFile = $outputDir . '/' . self::ATTRIBUTES_FILENAME; $this->delimiter = $config['delimiter']; $count = (int) $config['count']; $localizableProbability = (int) $config['localizable_probability']; $scopableProbability = (int) $config['scopable_probability']; $locScopableProbability = (int) $config['localizable_and_scopable_probability']; $identifier = $config['identifier_attribute']; $this->faker = Faker\Factory::create(); $this->attributes = []; $this->attributes[$identifier] = ['code' => $identifier, 'type' => 'pim_catalog_identifier', 'group' => $this->getRandomAttributeGroupCode()]; $forceAttributes = $config['force_attributes']; foreach ($forceAttributes as $forceAttribute) { list($code, $type) = explode('=', $forceAttribute); $this->attributes[trim($code)] = ['type' => trim($type), 'group' => $this->getRandomAttributeGroupCode()]; } for ($i = 0; $i < $count; $i++) { $attribute = []; $attribute['code'] = self::ATTRIBUTE_CODE_PREFIX . $i; $type = $this->getRandomAttributeType(); $attribute['type'] = $type; $attribute['group'] = $this->getRandomAttributeGroupCode(); foreach ($this->getLocalizedRandomLabels() as $localeCode => $label) { $attribute['label-' . $localeCode] = $label; } if ($this->faker->boolean($locScopableProbability)) { $attribute['localizable'] = 1; $attribute['scopable'] = 1; } else { $attribute['localizable'] = (int) $this->faker->boolean($localizableProbability); $attribute['scopable'] = (int) $this->faker->boolean($scopableProbability); } if ('pim_catalog_metric' === $type) { $attribute = array_merge($attribute, $this->getMetricProperties()); } if ('pim_catalog_image' === $type || 'pim_catalog_file' === $type) { $attribute = array_merge($attribute, $this->getMediaProperties()); } $this->attributes[$attribute['code']] = $attribute; $progress->advance(); } $headers = $this->getAllKeys($this->attributes); $this->writeCsvFile($this->attributes, $headers); return $this; }
/** * Generate value content based on backend type * * @param AbstractAttribute $attribute * @param string $key * * @return string */ protected function generateValueData(AbstractAttribute $attribute, $key) { $data = ""; if (isset($this->forcedValues[$attribute->getCode()])) { return $this->forcedValues[$attribute->getCode()]; } switch ($attribute->getBackendType()) { case "varchar": $validationRule = $attribute->getValidationRule(); switch ($validationRule) { case 'url': $data = $this->faker->url(); break; default: $data = $this->faker->sentence(); break; } break; case "text": $data = $this->faker->sentence(); break; case "date": $data = $this->faker->dateTimeBetween($attribute->getDateMin(), $attribute->getDateMax()); $data = $data->format('Y-m-d'); break; case "metric": case "decimal": case "prices": if ($attribute->getBackendType() && preg_match('/-' . self::METRIC_UNIT . '$/', $key)) { $data = $attribute->getDefaultMetricUnit(); } else { $min = $attribute->getNumberMin() != null ? $attribute->getNumberMin() : self::DEFAULT_NUMBER_MIN; $max = $attribute->getNumberMax() != null ? $attribute->getNumberMax() : self::DEFAULT_NUMBER_MAX; $decimals = $attribute->isDecimalsAllowed() ? self::DEFAULT_NB_DECIMALS : 0; $data = $this->faker->randomFloat($decimals, $min, $max); } break; case "boolean": $data = $this->faker->boolean() ? "1" : "0"; break; case "option": case "options": $options = []; foreach ($attribute->getOptions() as $option) { $options[] = $option; } $option = $this->faker->randomElement($options); if (is_object($option)) { $data = $option->getCode(); } break; default: $data = ''; break; } return (string) $data; }
/** * @param FactoryInterface $userFactory * @param FactoryInterface $customerFactory * @param RepositoryInterface $currencyRepository */ public function __construct(FactoryInterface $userFactory, FactoryInterface $customerFactory, RepositoryInterface $currencyRepository) { $this->userFactory = $userFactory; $this->customerFactory = $customerFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('email', function (Options $options) { return $this->faker->email; })->setDefault('first_name', function (Options $options) { return $this->faker->firstName; })->setDefault('last_name', function (Options $options) { return $this->faker->lastName; })->setDefault('currency_code', LazyOption::randomOne($currencyRepository))->setAllowedTypes('currency_code', ['null', 'string', CurrencyInterface::class])->setNormalizer('currency_code', LazyOption::findOneBy($currencyRepository, 'code'))->setNormalizer('currency_code', function (Options $options, CurrencyInterface $currency) { return $currency->getCode(); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('admin', false)->setAllowedTypes('admin', 'bool')->setDefault('password', function (Options $options) { return $this->faker->password; }); }
/** * @param ChannelFactoryInterface $channelFactory * @param RepositoryInterface $localeRepository * @param RepositoryInterface $currencyRepository * @param RepositoryInterface $paymentMethodRepository * @param RepositoryInterface $shippingMethodRepository */ public function __construct(ChannelFactoryInterface $channelFactory, RepositoryInterface $localeRepository, RepositoryInterface $currencyRepository, RepositoryInterface $paymentMethodRepository, RepositoryInterface $shippingMethodRepository) { $this->channelFactory = $channelFactory; $this->faker = \Faker\Factory::create(); $this->optionsResolver = (new OptionsResolver())->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('hostname', function (Options $options) { return $options['code'] . '.localhost'; })->setDefault('color', function (Options $options) { return $this->faker->colorName; })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('tax_calculation_strategy', 'order_items_based')->setAllowedTypes('tax_calculation_strategy', 'string')->setDefault('default_locale', function (Options $options) { return $this->faker->randomElement($options['locales']); })->setAllowedTypes('default_locale', LocaleInterface::class)->setNormalizer('default_locale', LazyOption::findOneBy($localeRepository, 'code'))->setDefault('locales', LazyOption::all($localeRepository))->setAllowedTypes('locales', 'array')->setNormalizer('locales', LazyOption::findBy($localeRepository, 'code'))->setDefault('default_currency', function (Options $options) { return $this->faker->randomElement($options['currencies']); })->setAllowedTypes('default_currency', CurrencyInterface::class)->setNormalizer('default_currency', LazyOption::findOneBy($currencyRepository, 'code'))->setDefault('currencies', LazyOption::all($currencyRepository))->setAllowedTypes('currencies', 'array')->setNormalizer('currencies', LazyOption::findBy($currencyRepository, 'code'))->setDefault('payment_methods', LazyOption::all($paymentMethodRepository))->setAllowedTypes('payment_methods', 'array')->setNormalizer('payment_methods', LazyOption::findBy($paymentMethodRepository, 'code'))->setDefault('shipping_methods', LazyOption::all($shippingMethodRepository))->setAllowedTypes('shipping_methods', 'array')->setNormalizer('shipping_methods', LazyOption::findBy($shippingMethodRepository, 'code'))->setDefault('theme_name', null); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('description', function (Options $options) { return $this->faker->sentence(); })->setDefault('gateway', 'offline')->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setAllowedTypes('enabled', 'bool'); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('amount', function (Options $options) { return $this->faker->randomFloat(2, 0, 0.4); })->setAllowedTypes('amount', 'float')->setDefault('included_in_price', function (Options $options) { return $this->faker->boolean(); })->setAllowedTypes('included_in_price', 'bool')->setDefault('calculator', 'default')->setDefault('zone', LazyOption::randomOne($this->zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($this->zoneRepository, 'code'))->setDefault('category', LazyOption::randomOne($this->taxCategoryRepository))->setAllowedTypes('category', ['null', 'string', TaxCategoryInterface::class])->setNormalizer('category', LazyOption::findOneBy($this->taxCategoryRepository, 'code')); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('name', $this->faker->words(3, true))->setDefault('description', $this->faker->sentence())->setDefault('usage_limit', null)->setDefault('coupon_based', false)->setDefault('exclusive', $this->faker->boolean(25))->setDefault('priority', 0)->setDefault('starts_at', null)->setAllowedTypes('starts_at', ['null', 'string'])->setDefault('ends_at', null)->setAllowedTypes('ends_at', ['null', 'string'])->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setDefined('rules')->setNormalizer('rules', function (Options $options, array $rules) { if (empty($rules)) { return [[]]; } return $rules; })->setDefined('actions')->setNormalizer('actions', function (Options $options, array $actions) { if (empty($actions)) { return [[]]; } return $actions; }); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('hostname', function (Options $options) { return $options['code'] . '.localhost'; })->setDefault('color', function (Options $options) { return $this->faker->colorName; })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('tax_calculation_strategy', 'order_items_based')->setAllowedTypes('tax_calculation_strategy', 'string')->setDefault('default_locale', function (Options $options) { return $this->faker->randomElement($options['locales']); })->setAllowedTypes('default_locale', ['string', LocaleInterface::class])->setNormalizer('default_locale', LazyOption::findOneBy($this->localeRepository, 'code'))->setDefault('locales', LazyOption::all($this->localeRepository))->setAllowedTypes('locales', 'array')->setNormalizer('locales', LazyOption::findBy($this->localeRepository, 'code'))->setDefault('base_currency', function (Options $options) { return $this->faker->randomElement($options['currencies']); })->setAllowedTypes('base_currency', ['string', CurrencyInterface::class])->setNormalizer('base_currency', LazyOption::findOneBy($this->currencyRepository, 'code'))->setDefault('currencies', LazyOption::all($this->currencyRepository))->setAllowedTypes('currencies', 'array')->setNormalizer('currencies', LazyOption::findBy($this->currencyRepository, 'code'))->setDefault('theme_name', null); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('description', function (Options $options) { return $this->faker->sentence(); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('zone', LazyOption::randomOne($this->zoneRepository))->setAllowedTypes('zone', ['null', 'string', ZoneInterface::class])->setNormalizer('zone', LazyOption::findOneBy($this->zoneRepository, 'code'))->setDefined('shipping_category')->setAllowedTypes('shipping_category', ['null', 'string', ShippingCategoryInterface::class])->setNormalizer('shipping_category', LazyOption::findOneBy($this->shippingCategoryRepository, 'code'))->setDefault('calculator', function (Options $options) { $configuration = []; /** @var ChannelInterface $channel */ foreach ($options['channels'] as $channel) { $configuration[$channel->getCode()] = ['amount' => $this->faker->randomNumber(4)]; } return ['type' => DefaultCalculators::FLAT_RATE, 'configuration' => $configuration]; })->setDefault('channels', LazyOption::all($this->channelRepository))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code')); }
/** * Only seed shops. * * @param Shop $owner */ private function seedAttributes($owner) { if (!$owner instanceof Shop) { return; } if ($this->faker->boolean(20)) { return; } $attributeGroups = $owner->attributeGroups()->saveMany(factory(AttributeGroup::class, $this->faker->numberBetween(2, 4))->make()); $attributeGroups->each(function (AttributeGroup $attributeGroup) { $attributeGroup->attributeOptions()->saveMany(factory(AttributeOption::class, $this->faker->numberBetween(2, 4))->make()); }); $variantManager = app(\App\Modules\ProductModule\Managers\VariantManager::class); /** @var Product[] $products */ $products = $owner->products()->get(); foreach ($products as $product) { if ($this->faker->boolean(20)) { continue; } $options = $attributeGroups->random(2)->pluck('attributeOptions')->flatten(1); $product->attributeOptions()->sync($options->pluck('id')->toArray()); $variantManager->refreshVariants($product); } }
/** * Generate a boolean product value data * * @return string */ protected function generateBooleanData() { return $this->faker->boolean() ? "1" : "0"; }
public function newRandomActivity($person) { $activity = (new Activity())->setUser($this->getRandomUser())->setPerson($person)->setDate($this->faker->dateTimeThisYear())->setDurationTime($this->faker->dateTime(36000))->setType($this->getRandomActivityType())->setReason($this->getRandomActivityReason())->setScope($this->getRandomScope())->setAttendee($this->faker->boolean())->setRemark('A remark'); return $activity; }
/** * Gets a random boolean value * * @param Faker\Generator * @return boolean */ public function getFakeData(Generator $faker) { return $faker->boolean(); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->setDefault('name', function (Options $options) { return $this->faker->words(3, true); })->setDefault('code', function (Options $options) { return StringInflector::nameToCode($options['name']); })->setDefault('enabled', function (Options $options) { return $this->faker->boolean(90); })->setAllowedTypes('enabled', 'bool')->setDefault('short_description', function (Options $options) { return $this->faker->paragraph; })->setDefault('description', function (Options $options) { return $this->faker->paragraphs(3, true); })->setDefault('main_taxon', LazyOption::randomOne($this->taxonRepository))->setAllowedTypes('main_taxon', ['null', 'string', TaxonInterface::class])->setNormalizer('main_taxon', LazyOption::findOneBy($this->taxonRepository, 'code'))->setDefault('taxons', LazyOption::randomOnes($this->taxonRepository, 3))->setAllowedTypes('taxons', 'array')->setNormalizer('taxons', LazyOption::findBy($this->taxonRepository, 'code'))->setDefault('channels', LazyOption::randomOnes($this->channelRepository, 3))->setAllowedTypes('channels', 'array')->setNormalizer('channels', LazyOption::findBy($this->channelRepository, 'code'))->setDefault('variant_selection_method', ProductInterface::VARIANT_SELECTION_MATCH)->setAllowedValues('variant_selection_method', [ProductInterface::VARIANT_SELECTION_MATCH, ProductInterface::VARIANT_SELECTION_CHOICE])->setDefault('product_attributes', [])->setAllowedTypes('product_attributes', 'array')->setNormalizer('product_attributes', function (Options $options, array $productAttributes) { $productAttributesValues = []; foreach ($productAttributes as $code => $value) { /** @var ProductAttributeInterface $productAttribute */ $productAttribute = $this->productAttributeRepository->findOneBy(['code' => $code]); Assert::notNull($productAttribute); /** @var ProductAttributeValueInterface $productAttributeValue */ $productAttributeValue = $this->productAttributeValueFactory->createNew(); $productAttributeValue->setAttribute($productAttribute); $productAttributeValue->setValue($value ?: $this->getRandomValueForProductAttribute($productAttribute)); $productAttributesValues[] = $productAttributeValue; } return $productAttributesValues; })->setDefault('product_options', [])->setAllowedTypes('product_options', 'array')->setNormalizer('product_options', LazyOption::findBy($this->productOptionRepository, 'code'))->setDefault('images', [])->setAllowedTypes('images', 'array'); }
/** * @return array */ protected function generateCreateParams() { return ['meetingName' => $this->faker->name, 'meetingId' => $this->faker->uuid, 'attendeePassword' => $this->faker->password, 'moderatorPassword' => $this->faker->password, 'autoStartRecording' => $this->faker->boolean(50), 'dialNumber' => $this->faker->phoneNumber, 'voiceBridge' => $this->faker->randomNumber(5), 'webVoice' => $this->faker->word, 'logoutUrl' => $this->faker->url, 'maxParticipants' => $this->faker->numberBetween(2, 100), 'record' => $this->faker->boolean(50), 'duration' => $this->faker->numberBetween(0, 6000), 'welcomeMessage' => $this->faker->sentence, 'allowStartStopRecording' => $this->faker->boolean(50), 'moderatorOnlyMessage' => $this->faker->sentence, 'meta_presenter' => $this->faker->name]; }