本文整理汇总了PHP中Faker\Generator::boolean方法的典型用法代码示例。如果您正苦于以下问题:PHP Generator::boolean方法的具体用法?PHP Generator::boolean怎么用?PHP Generator::boolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Faker\Generator
的用法示例。
在下文中一共展示了Generator::boolean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
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);
}
示例2: run
/**
* 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);
}
}
}
示例3: __construct
/**
* @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);
}
示例4: randomWinType
/**
* @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;
}
示例5: __construct
/**
* @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');
}
示例6: __construct
/**
* @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'));
}
示例7: __construct
/**
* @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');
}
示例8: __construct
/**
* @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]];
});
}
示例9: run
/**
* 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);
}
}
}
示例10: completeCheckout
/**
* @param OrderInterface $order
*/
private function completeCheckout(OrderInterface $order)
{
if ($this->faker->boolean(25)) {
$order->setNotes($this->faker->sentence);
}
$this->applyCheckoutStateTransition($order, OrderCheckoutTransitions::TRANSITION_COMPLETE);
}
示例11: __construct
/**
* @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'));
}
示例12: __construct
/**
* @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');
}
示例13: generate
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;
}
示例14: shouldHandle
/**
* 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;
}
示例15: run
/**
* 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);
}
}
}