mbezhanov / faker-provider-collection
Faker库的定制提供者集合
2.0.2
2023-12-26 14:31 UTC
Requires
- php: ^7.4|^8.0
- fakerphp/faker: ^1.13
Requires (Dev)
- php-mock/php-mock: ^2.3
- phpunit/phpunit: ^9.5
README
一个不断增长的用于fakerphp/faker的有用提供者集合,主要从stympy/faker Ruby库移植到PHP。
内容
安装
composer require mbezhanov/faker-provider-collection
基本用法
您可以使用ProviderCollectionHelper
实用类快速将所有提供者添加到Faker生成器中
<?php $faker = \Faker\Factory::create(); \Bezhanov\Faker\ProviderCollectionHelper::addAllProvidersTo($faker);
格式化器
以下是默认语言环境下的捆绑格式化器列表。
Bezhanov\Faker\Provider\Avatar
使用RoboHash网络服务生成头像URL。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Avatar($faker)); $faker->avatar; // https://robohash.org/repellat-veritatis-consequatur.png?size=300x300&set=set1 $faker->avatar('foo'); // https://robohash.org/foo.png?size=300x300&set=set1 $faker->avatar('foo', '300x300'); // https://robohash.org/foo.png?size=300x300&set=set1 $faker->avatar('foo', '300x300', 'jpg'); // https://robohash.org/foo.jpg?size=300x300&set=set1 $faker->avatar('foo', '300x300', 'jpg', 'set2'); // https://robohash.org/foo.jpg?size=300x300&set=set2 $faker->avatar('foo', '300x300', 'jpg', 'set2', 'bg2'); // https://robohash.org/foo.jpg?size=300x300&set=set2&bgset=bg2
Bezhanov\Faker\Provider\Commerce
生成电子商务网站和在线商店的产品和部门数据。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Commerce($faker)); $faker->promotionCode; // KillerPromotion257835 $faker->department; // Kids & Games $faker->department(6); // Games, Industrial, Books & Automotive $faker->department(3, true); // Jewelry, Music & Shoes $faker->category; // Computers $faker->productName; // Small Rubber Bottle
Bezhanov\Faker\Provider\Device
生成随机移动设备规格。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Device($faker)); $faker->deviceBuildNumber; // 186 $faker->deviceManufacturer; // Apple $faker->deviceModelName; // iPhone 4 $faker->devicePlatform; // Ubuntu Touch $faker->deviceSerialNumber; // ejfjnRNInxh0363JC2WM $faker->deviceVersion; // 812
Bezhanov\Faker\Provider\Demographic
生成随机的统计数据,如:种族、性别、昵称、教育程度、身高。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Demographic($faker)); $faker->race; // Asian $faker->educationalAttainment; // Master's degree $faker->demonym; // Bulgarian $faker->maritalStatus; // Married $faker->gender; // Female $faker->height; // 1.99 $faker->height(Demographic::UNIT_TYPE_IMPERIAL); // 7 ft, 2 in
Bezhanov\Faker\Provider\Educator
生成中学和大学名称以及课程名称。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Educator($faker)); $faker->university; // Clearcourt University $faker->secondarySchool; // Mallowpond High $faker->course; // Bachelor of Forensic Science $faker->campus; // Brighthurst Campus
Bezhanov\Faker\Provider\Food
生成成分名称、香料名称和食谱度量。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Food($faker)); $faker->ingredient; // Hazelnut $faker->spice; // Chamomile $faker->measurement; // 1 pint
Bezhanov\Faker\Provider\Medicine
生成假药名称。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Medicine($faker)); $faker->medicine; // Amphevorin
Bezhanov\Faker\Provider\Placeholder
使用Placeholder.com图像占位符服务生成占位符图像的URL。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Placeholder($faker)); $faker->placeholder(); // https://placehold.it/300x300.png $faker->placeholder('250x250'); // https://placehold.it/250x250.png $faker->placeholder('250x250', 'jpg'); // https://placehold.it/250x250.jpg $faker->placeholder('250x250', 'jpg', 'ff0000'); // https://placehold.it/250x250.jpg/ff0000 $faker->placeholder('250x250', 'jpg', 'f00', '000000'); // https://placehold.it/250x250.jpg/f00/000000 $faker->placeholder('250x250', 'jpg', 'ff0000', '000', 'test'); // https://placehold.it/250x250.jpg/ff0000/000?text=test
Bezhanov\Faker\Provider\Science
生成科学家和化学元素名称。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Science($faker)); $faker->chemicalElement; // Radium $faker->chemicalElementSymbol; // Fe $faker->scientist; // Max Planck
Bezhanov\Faker\Provider\Space
生成天体名称、距离测量、宇宙飞船等。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Space($faker)); $faker->planet; // Neptune $faker->moon; // Europa $faker->galaxy; // Andromeda $faker->nebula; // Orion Nebula $faker->starCluster; // Palomar 6 $faker->constellation; // Ursa Major $faker->star; // Luyten 726-8B $faker->agency; // Japan Aerospace Exploration Agency $faker->agencyAbv; // NASA $faker->nasaSpaceCraft; // Atlantis $faker->spaceCompany; // SpaceX $faker->distanceMeasurement; // 43 kiloparsecs $faker->meteorite; // Qidong $faker->launchVehicle; // Saturn IV
Bezhanov\Faker\Provider\Species
生成虚构鸟类、动物和植物物种的学名。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Species($faker)); echo $faker->bird . PHP_EOL; // Rostratula subis echo $faker->creature . PHP_EOL; // Latrodectus indri echo $faker->plant . PHP_EOL; // Pyrus filiformis
Bezhanov\Faker\Provider\Team
生成运动和运动队名称。
<?php $faker = \Faker\Factory::create(); $faker->addProvider(new \Bezhanov\Faker\Provider\Team($faker)); $faker->team; // Oregon Tigers $faker->sport; // soccer
集成
贡献
欢迎所有贡献。在打开PR之前,请确保所有测试都通过,并且代码覆盖率令人满意。
phpunit tests --coverage-html coverage