本文整理汇总了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);
}
示例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();
}
示例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]);
}
示例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]];
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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());
}
}
}
示例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]);
}
示例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');
});
}
示例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();
}
}
示例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);
}
示例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]);
}
示例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;
}