当前位置: 首页>>代码示例>>PHP>>正文


PHP Generator::numberBetween方法代码示例

本文整理汇总了PHP中Faker\Generator::numberBetween方法的典型用法代码示例。如果您正苦于以下问题:PHP Generator::numberBetween方法的具体用法?PHP Generator::numberBetween怎么用?PHP Generator::numberBetween使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Faker\Generator的用法示例。


在下文中一共展示了Generator::numberBetween方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createExpense

 public function createExpense(AcceptanceTester $I)
 {
     $I->wantTo('Create an expense');
     $vendorName = $this->faker->name;
     $clientEmail = $this->faker->safeEmail;
     $amount = $this->faker->numberBetween(10, 20);
     // create vendor
     $I->amOnPage('/vendors/create');
     $I->fillField(['name' => 'name'], $vendorName);
     $I->click('Save');
     $I->see($vendorName);
     $vendorId = $I->grabFromDatabase('vendors', 'id', ['name' => $vendorName]);
     // create client
     $I->amOnPage('/clients/create');
     $I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
     $I->click('Save');
     $I->see($clientEmail);
     // create expense
     $I->amOnPage('/expenses/create');
     $I->fillField(['name' => 'amount'], $amount);
     $I->selectDropdown($I, $vendorName, '.vendor-select .dropdown-toggle');
     $I->selectDropdown($I, $clientEmail, '.client-select .dropdown-toggle');
     $I->click('Save');
     $I->seeInDatabase('expenses', ['vendor_id' => $vendorId]);
     // invoice expense
     $I->executeJS('submitAction(\'invoice\')');
     $I->click('Save');
     $I->wait(1);
     $I->see($clientEmail);
     $I->see($amount);
 }
开发者ID:sseshachala,项目名称:invoiceninja,代码行数:31,代码来源:ExpenseCest.php

示例2: run

 /**
  * 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();
 }
开发者ID:gez-studio,项目名称:gez-mall,代码行数:17,代码来源:PostSeeder.php

示例3: load

 /**
  * {@inheritdoc}
  */
 public function load(array $options)
 {
     $options = $this->optionsResolver->resolve($options);
     $this->taxonFixture->load(['custom' => [['code' => 'category', 'name' => 'Category', 'children' => [['code' => 'books', 'name' => 'Books']]]]]);
     $this->productAttributeFixture->load(['custom' => [['name' => 'Book author', 'code' => 'book_author', 'type' => TextAttributeType::TYPE], ['name' => 'Book ISBN', 'code' => 'book_isbn', 'type' => TextAttributeType::TYPE], ['name' => 'Book pages', 'code' => 'book_pages', 'type' => IntegerAttributeType::TYPE]]]);
     $products = [];
     $productsNames = $this->getUniqueNames($options['amount']);
     for ($i = 0; $i < $options['amount']; ++$i) {
         $authorName = $this->faker->name;
         $products[] = ['name' => sprintf('Book "%s" by %s', $productsNames[$i], $authorName), 'code' => $this->faker->uuid, 'main_taxon' => 'books', 'taxons' => ['books'], 'product_attributes' => ['book_author' => $authorName, 'book_isbn' => $this->faker->isbn13, 'book_pages' => $this->faker->numberBetween(42, 1024)], 'images' => ['main' => sprintf('%s/../Resources/fixtures/%s', __DIR__, 'books.jpg'), 'thumbnail' => sprintf('%s/../Resources/fixtures/%s', __DIR__, 'books.jpg')]];
     }
     $this->productFixture->load(['custom' => $products]);
 }
开发者ID:loic425,项目名称:Sylius,代码行数:16,代码来源:BookProductFixture.php

示例4: seed

 /**
  * @param PDO $db
  * @return void
  */
 public function seed(PDO $db)
 {
     $db->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT, age INTEGER, gender TEXT)');
     $stmt = $db->prepare('INSERT INTO users (name, age, gender) VALUES (:name, :age, :gender)');
     $names = [];
     for ($i = 0; $i < $this->faker->numberBetween(5, 15); $i++) {
         $name = $this->faker->name;
         $age = rand(18, 90);
         $gender = rand(0, 100) % 2 ? 'male' : 'female';
         $stmt->execute([':name' => $name, ':age' => $age, ':gender' => $gender]);
         $id = $db->lastInsertId();
         $names[$id] = $name;
     }
     $randomId = array_rand($names);
     $this->randomRecord = ['id' => $randomId, 'name' => $names[$randomId]];
 }
开发者ID:php-school,项目名称:learn-you-php,代码行数:20,代码来源:DatabaseRead.php

示例5: generate

 /**
  * {@inheritdoc}
  */
 public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null)
 {
     $this->attributeGroupsFile = $outputDir . '/' . static::ATTRIBUTE_GROUP_FILENAME;
     $count = (int) $config['count'];
     $this->faker = Faker\Factory::create();
     $this->attributeGroups = [];
     for ($i = 0; $i < $count; $i++) {
         $attributeGroup = [];
         $attributeGroup['sortOrder'] = $this->faker->numberBetween(1, 10);
         $attributeGroup['labels'] = $this->getLocalizedRandomLabels();
         $this->attributeGroups[self::ATTR_GROUP_CODE_PREFIX . $i] = $attributeGroup;
         $progress->advance();
     }
     $this->writeYamlFile(['attribute_groups' => $this->attributeGroups], $this->attributeGroupsFile);
     return $this;
 }
开发者ID:norfil,项目名称:DataGeneratorBundle,代码行数:19,代码来源:AttributeGroupGenerator.php

示例6: 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;
 }
开发者ID:EcomDev,项目名称:mysql-performance-benchmark,代码行数:30,代码来源:Generator.php

示例7: configureOptions

 /**
  * {@inheritdoc}
  */
 protected function configureOptions(OptionsResolver $resolver)
 {
     $resolver->setDefault('title', function (Options $options) {
         return $this->faker->words(3, true);
     })->setDefault('rating', function (Options $options) {
         return $this->faker->numberBetween(1, 5);
     })->setDefault('comment', function (Options $options) {
         return $this->faker->sentences(3, true);
     })->setDefault('author', LazyOption::randomOne($this->customerRepository))->setNormalizer('author', LazyOption::findOneBy($this->customerRepository, 'email'))->setDefault('product', LazyOption::randomOne($this->productRepository))->setNormalizer('product', LazyOption::findOneBy($this->productRepository, 'code'))->setDefault('status', null);
 }
开发者ID:NeverResponse,项目名称:Sylius,代码行数:13,代码来源:ProductReviewExampleFactory.php

示例8: generate

 /**
  * {@inheritdoc}
  */
 public function generate(array $config, $outputDir, ProgressHelper $progress, array $options = null)
 {
     $countPerAttribute = (int) $config['count_per_attribute'];
     $this->delimiter = $config['delimiter'];
     $this->attributeOptionsFile = $outputDir . '/' . static::ATTRIBUTE_OPTIONS_FILENAME;
     foreach ($this->getSelectAttributes() as $attribute) {
         for ($i = 0; $i < $countPerAttribute; $i++) {
             $attributeOption = [];
             $attributeOption['attribute'] = $attribute->getCode();
             $attributeOption['code'] = static::ATTRIBUTE_OPTION_CODE_PREFIX . $attribute->getCode() . $i;
             $attributeOption['sort_order'] = $this->faker->numberBetween(1, $countPerAttribute);
             foreach ($this->getLocalizedRandomLabels() as $localeCode => $label) {
                 $attributeOption['label-' . $localeCode] = $label;
             }
             $this->attributeOptions[$attributeOption['code']] = $attributeOption;
         }
     }
     $headers = $this->getAllKeys($this->attributeOptions);
     $this->writeCsvFile($this->attributeOptions, $headers);
     return $this;
 }
开发者ID:norfil,项目名称:DataGeneratorBundle,代码行数:24,代码来源:AttributeOptionGenerator.php

示例9: testResponse

 public function testResponse()
 {
     foreach (array(PaymentStatus::SUCCESS, PaymentStatus::DECLINED, PaymentStatus::INCOMPLETE) as $status) {
         $response = array('orderID' => $this->faker->randomNumber('####'), 'currency' => 'CHF', 'amount' => $this->faker->randomFloat(2, 1, 100), 'PM' => $this->faker->randomElement(array(PaymentMethod::POSTFINANCE_EFINANCE, PaymentMethod::CREDITCARD, PaymentMethod::POSTFINANCE_CARD)), 'ACCEPTANCE' => 'test123', 'STATUS' => $status, 'CARDNO' => 'XXXXXXXXXXXX' . $this->faker->randomNumber('####'), 'ED' => $this->faker->numberBetween(10, 12) . $this->faker->numberBetween(10, 99), 'CN' => $this->faker->name, 'TRXDATE' => $this->faker->date('m/d/Y'), 'PAYID' => $this->faker->randomNumber('########'), 'IPCTY' => $this->faker->countryCode, 'CCCTY' => $this->faker->countryCode, 'ECI' => '5', 'CVCCheck' => 'NO', 'AAVCheck' => 'NO', 'VC' => 'NO', 'IP' => $this->faker->ipv4, 'NCERROR' => '0');
         if ($response['PM'] === PaymentMethod::CREDITCARD) {
             $response['BRAND'] = $this->faker->randomElement(array(Brand::MASTERCARD, Brand::VISA));
         } elseif ($response['PM'] === PaymentMethod::POSTFINANCE_CARD) {
             $response['BRAND'] = PaymentMethod::POSTFINANCE_CARD;
         } elseif ($response['PM'] === PaymentMethod::POSTFINANCE_EFINANCE) {
             $response['BRAND'] = PaymentMethod::POSTFINANCE_EFINANCE;
         }
         $response['SHASIGN'] = $this->createHash($response, $this->environment->getShaOut(), $this->environment->getHashAlgorithm());
         $ePayment = new PostFinanceEPayment($this->environment);
         $response = $ePayment->getResponse($response);
         $this->assertTrue($response instanceof Response);
         if ($status === PaymentStatus::SUCCESS) {
             $this->assertFalse($response->hasError());
         } else {
             $this->assertTrue($response->hasError());
         }
     }
 }
开发者ID:whatwedo,项目名称:postfinance-e-payment,代码行数:22,代码来源:PostFinanceEPaymentTest.php

示例10: load

 /**
  * {@inheritdoc}
  */
 public function load(array $options)
 {
     $options = $this->optionsResolver->resolve($options);
     $this->taxonFixture->load(['custom' => [['code' => 'category', 'name' => 'Category', 'children' => [['code' => 'books', 'name' => 'Books']]]]]);
     $this->productAttributeFixture->load(['custom' => [['name' => 'Book author', 'code' => 'BOOK-AUTHOR', 'type' => TextAttributeType::TYPE], ['name' => 'Book ISBN', 'code' => 'BOOK-ISBN', 'type' => TextAttributeType::TYPE], ['name' => 'Book pages', 'code' => 'BOOK-PAGES', 'type' => IntegerAttributeType::TYPE]]]);
     $this->productArchetypeFixture->load(['custom' => [['name' => 'Book', 'code' => 'BOOK', 'product_attributes' => ['BOOK-AUTHOR', 'BOOK-ISBN', 'BOOK-PAGES'], 'product_options' => []]]]);
     $products = [];
     for ($i = 0; $i < $options['amount']; ++$i) {
         $name = $this->faker->name;
         $products[] = ['name' => sprintf('Book "%s" by %s', $this->faker->word, $name), 'code' => $this->faker->uuid, 'main_taxon' => 'books', 'product_archetype' => 'BOOK', 'taxons' => ['books'], 'product_attributes' => ['BOOK-AUTHOR' => $name, 'BOOK-ISBN' => $this->faker->isbn13, 'BOOK-PAGES' => $this->faker->numberBetween(42, 1024)], 'images' => [sprintf('%s/../Resources/fixtures/%s', __DIR__, 'books.jpg')]];
     }
     $this->productFixture->load(['custom' => $products]);
 }
开发者ID:TeamNovatek,项目名称:Sylius,代码行数:16,代码来源:BookProductFixture.php

示例11: createQuote

 public function createQuote(AcceptanceTester $I)
 {
     $clientEmail = $this->faker->safeEmail;
     $productKey = $this->faker->text(10);
     $I->wantTo('create a quote');
     // create client
     $I->amOnPage('/clients/create');
     $I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
     $I->click('Save');
     $I->see($clientEmail);
     // create product
     $I->amOnPage('/products/create');
     $I->fillField(['name' => 'product_key'], $productKey);
     $I->fillField(['name' => 'notes'], $this->faker->text(80));
     $I->fillField(['name' => 'cost'], $this->faker->numberBetween(1, 20));
     $I->click('Save');
     $I->wait(1);
     //$I->see($productKey);
     // create quote
     $I->amOnPage('/quotes/create');
     $I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
     $I->fillField('table.invoice-table tbody tr:nth-child(1) #product_key', $productKey);
     $I->click('table.invoice-table tbody tr:nth-child(1) .tt-selectable');
     $I->click('Save');
     $I->see($clientEmail);
     // enter payment
     $clientId = $I->grabFromDatabase('contacts', 'client_id', ['email' => $clientEmail]);
     $invoiceId = $I->grabFromDatabase('invoices', 'id', ['client_id' => $clientId]);
     $invitationKey = $I->grabFromDatabase('invitations', 'invitation_key', ['invoice_id' => $invoiceId]);
     $clientSession = $I->haveFriend('client');
     $clientSession->does(function (AcceptanceTester $I) use($invitationKey) {
         $I->amOnPage('/view/' . $invitationKey);
         $I->click('Approve');
         $I->see('This quote is approved');
     });
 }
开发者ID:hillelcoren,项目名称:invoice-ninja,代码行数:36,代码来源:QuoteCest.php

示例12: getRandomValueForProductAttribute

 /**
  * @param ProductAttributeInterface $productAttribute
  *
  * @return mixed
  */
 private function getRandomValueForProductAttribute(ProductAttributeInterface $productAttribute)
 {
     switch ($productAttribute->getStorageType()) {
         case ProductAttributeValueInterface::STORAGE_BOOLEAN:
             return $this->faker->boolean;
         case ProductAttributeValueInterface::STORAGE_INTEGER:
             return $this->faker->numberBetween(0, 10000);
         case ProductAttributeValueInterface::STORAGE_FLOAT:
             return $this->faker->randomFloat(4, 0, 10000);
         case ProductAttributeValueInterface::STORAGE_TEXT:
             return $this->faker->sentence;
         case ProductAttributeValueInterface::STORAGE_DATE:
         case ProductAttributeValueInterface::STORAGE_DATETIME:
             return $this->faker->dateTimeThisCentury;
         default:
             throw new \BadMethodCallException();
     }
 }
开发者ID:loic425,项目名称:Sylius,代码行数:23,代码来源:ProductExampleFactory.php

示例13: distributeRubrics

 private function distributeRubrics()
 {
     print_r("Distribute rubrics for company...");
     $companies = Company::find()->all();
     $rubrics = Rubric::findRecursive(array(), 'down', true);
     $rubrics_ids = ArrayHelper::getColumn($rubrics, 'id');
     $rubrics_ids_count = count($rubrics_ids);
     foreach ($companies as $company) {
         $this->faker->unique(true);
         $rubric_for_company_count = $this->faker->numberBetween(self::MIN_RUBRIC_FOR_COMPANY, self::MAX_RUBRIC_FOR_COMPANY);
         for ($i = 1; $i <= $rubric_for_company_count; $i++) {
             $company_rubric = new CompanyRubric();
             $company_rubric->company_id = $company->id;
             $company_rubric->rubric_id = $rubrics_ids[$this->faker->unique()->numberBetween(0, $rubrics_ids_count - 1)];
             $company_rubric->save();
         }
     }
     print_r("DONE" . PHP_EOL);
 }
开发者ID:novikovsergey,项目名称:doublegis,代码行数:19,代码来源:GeneratorController.php

示例14: load

 /**
  * {@inheritdoc}
  */
 public function load(array $options)
 {
     $options = $this->optionsResolver->resolve($options);
     $taxons = [];
     if (null === $this->taxonRepository->findOneBy(['code' => 'CATEGORY'])) {
         $taxons[] = ['name' => 'Category', 'code' => 'CATEGORY', 'parent' => null];
     }
     if (null === $this->taxonRepository->findOneBy(['code' => 'BRAND'])) {
         $taxons[] = ['name' => 'Brand', 'code' => 'BRAND', 'parent' => null];
     }
     $this->taxonFixture->load(['custom' => array_merge($taxons, [['name' => 'Books', 'code' => 'BOOKS', 'parent' => 'CATEGORY'], ['name' => 'BookMania', 'code' => 'BOOKMANIA', 'parent' => 'BRAND']])]);
     $this->productAttributeFixture->load(['custom' => [['name' => 'Book author', 'code' => 'BOOK-AUTHOR', 'type' => TextAttributeType::TYPE], ['name' => 'Book ISBN', 'code' => 'BOOK-ISBN', 'type' => TextAttributeType::TYPE], ['name' => 'Book pages', 'code' => 'BOOK-PAGES', 'type' => IntegerAttributeType::TYPE]]]);
     $this->productArchetypeFixture->load(['custom' => [['name' => 'Book', 'code' => 'BOOK', 'product_attributes' => ['BOOK-AUTHOR', 'BOOK-ISBN', 'BOOK-PAGES'], 'product_options' => []]]]);
     $products = [];
     for ($i = 0; $i < $options['amount']; ++$i) {
         $name = $this->faker->name;
         $products[] = ['name' => sprintf('Book "%s" by %s', $this->faker->word, $name), 'code' => $this->faker->uuid, 'main_taxon' => 'BOOKS', 'product_archetype' => 'BOOK', 'taxons' => ['BOOKS', 'BOOKMANIA'], 'product_attributes' => ['BOOK-AUTHOR' => $name, 'BOOK-ISBN' => $this->faker->isbn13, 'BOOK-PAGES' => $this->faker->numberBetween(42, 1024)], 'images' => [sprintf('%s/../Resources/fixtures/%s', __DIR__, 'books.jpg')]];
     }
     $this->productFixture->load(['custom' => $products]);
 }
开发者ID:okwinza,项目名称:Sylius,代码行数:23,代码来源:BookProductFixture.php

示例15: getRandomNumber

 /**
  * Get a random number, float or integer
  *
  * @param stdClass $schema
  * @param bool $float
  * @return float|int
  * @throws InvalidArgumentException
  */
 private function getRandomNumber(stdClass $schema, $float = false)
 {
     $multipleOf = $this->provider->getProperty($schema, 'multipleOf', $this->config->getMultipleOf());
     $maximum = $this->provider->getProperty($schema, 'maximum', $this->config->getMaximum());
     $minimum = $this->provider->getProperty($schema, 'minimum', $this->config->getMinimum());
     $exclusiveMaximum = $this->provider->getProperty($schema, 'exclusiveMaximum', false);
     $exclusiveMinimum = $this->provider->getProperty($schema, 'exclusiveMinimum', false);
     if (true === $exclusiveMaximum) {
         $maximum--;
     }
     if (true === $exclusiveMinimum) {
         $maximum++;
     }
     $decimals = $float ? $this->generator->numberBetween(0, 4) : 0;
     $modifier = 1 / pow(10, $decimals);
     $number = $float ? $this->generator->randomFloat($decimals, $minimum, $maximum) : $this->generator->numberBetween($minimum, $maximum);
     while ($number % $multipleOf !== 0) {
         $number += $modifier;
     }
     return $number;
 }
开发者ID:tebru,项目名称:swagger-faker,代码行数:29,代码来源:SchemaGenerator.php


注:本文中的Faker\Generator::numberBetween方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。