/** * @param FactoryInterface $taxonFactory * @param ObjectManager $taxonManager * @param RepositoryInterface $taxonRepository * @param RepositoryInterface $localeRepository */ public function __construct(FactoryInterface $taxonFactory, ObjectManager $taxonManager, RepositoryInterface $taxonRepository, RepositoryInterface $localeRepository) { $this->taxonFactory = $taxonFactory; $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('description', function (Options $options) { return $this->faker->paragraph; })->setDefault('parent', LazyOption::randomOneOrNull($taxonRepository, 70))->setAllowedTypes('parent', ['null', 'string', TaxonInterface::class])->setNormalizer('parent', function (Options $options, $previousValue) use($taxonManager) { $taxonManager->flush(); return $previousValue; })->setNormalizer('parent', LazyOption::findOneBy($taxonRepository, 'code')); }
/** * {@inheritdoc} */ protected function configureOptions(OptionsResolver $resolver) { $resolver->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('enabled', true)->setAllowedTypes('enabled', 'bool')->setDefault('password', 'password123')->setDefault('customer_group', LazyOption::randomOneOrNull($this->customerGroupRepository, 100))->setAllowedTypes('customer_group', ['null', 'string', CustomerGroupInterface::class])->setNormalizer('customer_group', LazyOption::findOneBy($this->customerGroupRepository, 'code')); }