本文整理汇总了PHP中Faker\Generator类的典型用法代码示例。如果您正苦于以下问题:PHP Generator类的具体用法?PHP Generator怎么用?PHP Generator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Generator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateProducts
public static function generateProducts(\Faker\Generator $generator)
{
$title_words = $generator->words(mt_rand(2, 5));
$title = implode(' ', $title_words);
$price = mt_rand(1, 10000);
return array('title' => $title, 'price' => $price);
}
示例2: test
public function test(TestCase $test, Generator $faker)
{
$value = $faker->randomElement(array_filter(array_keys($this->items)), function ($value) {
return !!$value;
});
return $test->select($value, $this->name);
}
示例3: testIdNumber
public function testIdNumber()
{
$faker = new Generator();
$faker->addProvider(new Person($faker));
$faker->seed(2);
$this->assertRegExp('/^[А-Я]{2}\\d{8}$/u', $faker->idNumber);
}
示例4: testLastKanaNameReturnsNagisa
public function testLastKanaNameReturnsNagisa()
{
$faker = new Generator();
$faker->addProvider(new Person($faker));
$faker->seed(1);
$this->assertEquals('ナギサ', $faker->lastKanaName);
}
示例5: setUp
public function setUp()
{
$faker = new Generator();
$faker->addProvider(new Barcode($faker));
$faker->seed(0);
$this->faker = $faker;
}
示例6: setUp
public function setUp()
{
$faker = new Generator();
$faker->addProvider(new Address($faker));
$faker->addProvider(new Person($faker));
$this->faker = $faker;
}
示例7: testTextMinLength
/**
* @expectedException \InvalidArgumentException
*/
public function testTextMinLength()
{
$generator = new Generator();
$generator->addProvider(new Text($generator));
$generator->seed(0);
$generator->realText(9);
}
示例8: testUuidExpectedSeed
public function testUuidExpectedSeed()
{
$faker = new Generator();
$faker->seed(123);
$this->assertEquals("8e2e0c84-50dd-367c-9e66-f3ab455c78d6", BaseProvider::uuid());
$this->assertEquals("073eb60a-902c-30ab-93d0-a94db371f6c8", BaseProvider::uuid());
}
示例9: testBirthNumber
public function testBirthNumber()
{
$faker = new Generator();
$faker->addProvider(new Person($faker));
$faker->addProvider(new Miscellaneous($faker));
for ($i = 0; $i < 1000; $i++) {
$birthNumber = $faker->birthNumber();
$birthNumber = str_replace('/', '', $birthNumber);
// check date
$year = intval(substr($birthNumber, 0, 2), 10);
$month = intval(substr($birthNumber, 2, 2), 10);
$day = intval(substr($birthNumber, 4, 2), 10);
// make 4 digit year from 2 digit representation
$year += $year < 54 ? 2000 : 1900;
// adjust special cases for month
if ($month > 50) {
$month -= 50;
}
if ($year >= 2004 && $month > 20) {
$month -= 20;
}
$this->assertTrue(checkdate($month, $day, $year), "Birth number {$birthNumber}: date {$year}/{$month}/{$day} is invalid.");
// check CRC if presented
if (strlen($birthNumber) == 10) {
$crc = intval(substr($birthNumber, -1), 10);
$refCrc = intval(substr($birthNumber, 0, -1), 10) % 11;
if ($refCrc == 10) {
$refCrc = 0;
}
$this->assertEquals($crc, $refCrc, "Birth number {$birthNumber}: checksum {$crc} doesn't match expected {$refCrc}.");
}
}
}
示例10: testSave
/**
* @covers \Glue\Storage\Index::save
*/
public function testSave()
{
$data = implode(' ', $this->faker->sentences());
$result = $this->index->save($this->faker->uuid, $this->testData['length'], strlen($data));
$this->assertNotEquals(false, $result);
$this->assertInternalType('int', $result);
}
示例11: testState
public function testState()
{
$state = $this->faker->state();
$this->assertNotEmpty($state);
$this->assertInternalType('string', $state);
$this->assertRegExp('/[A-Z][a-z]+/', $state);
}
示例12: 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);
}
示例13: testAreaSuffix
public function testAreaSuffix()
{
$areaSuffix = $this->faker->areaSuffix();
$this->assertNotEmpty($areaSuffix);
$this->assertInternalType('string', $areaSuffix);
$this->assertRegExp('/[A-Z][a-z]+/', $areaSuffix);
}
示例14: getArgs
/**
* @return array
*/
public function getArgs()
{
$path = $this->getTemporaryPath();
$paragraphs = $this->faker->paragraphs(rand(5, 50), true);
$this->filesystem->dumpFile($path, $paragraphs);
return [$path];
}
示例15: 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);
}
}
}