Additional providers for fzaninotto/faker
This package provides set of additional providers for faker package. Also it provides service-provider for Laravel framework.
Require this package with composer using the following command:
$ composer require --dev avto-dev/faker-providers "^3.2"
Installed
composer
is required (how to install composer).
You need to fix the major version of package.
After installation you can "publish" configuration file (./config/faker.php
) using next command:
$ ./artisan vendor:publish --provider="AvtoDev\FakerProviders\Frameworks\Laravel\ServiceProvider"
And add any additional faker providers in ./config/faker.php
configuration file, if you want.
For providers using you must register them at first:
<?php
use Faker\Generator as FakerGenerator;
use AvtoDev\FakerProviders\ExtendedFaker;
/** @var FakerGenerator|ExtendedFaker $faker */
$faker = new FakerGenerator;
$provider = \AvtoDev\FakerProviders\Providers\Cars\MarkAndModelProvider::class;
$faker->addProvider(new $provider($faker));
echo $faker->carMarkAndModel; // BMW X3
If you use this package in laravel application - all providers will be registered automatically. Then you can use all provided methods, for example, in model factory:
<?php // File: ./database/factories/CarFactory.php
use App\Models\Car;
use Faker\Generator as Faker;
use Illuminate\Database\Eloquent\Factory as EloquentFactory;
/** @var EloquentFactory $factory */
$factory->define(Car::class, function (Faker $faker) {
/** @var Faker|\AvtoDev\FakerProviders\ExtendedFaker $faker */
return [
'vin' => $faker->vinCode,
'mark' => $mark = $faker->carMark,
'model' => $faker->carModel($mark),
];
});
Comment
/** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
is required for correct type-hinting
All providers located in AvtoDev\FakerProviders\Providers
namespace.
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->carMarkAndModel; // Skoda Octavia
$faker->carMark; // Daewoo
$faker->carModel; // Juke
$faker->carModel('Honda'); // Civic Type R
$faker->carGeneration; // IV Restyling
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->bodyCode; // ILМ842 6262494
$faker->invalidBodyCode; // 246553
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->chassisCode; // СM3654637018
$faker->invalidChassisCode; // 20567820000000000
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->grzCode; // Х133АМ02
$faker->invalidGrzCode; // У777
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->ptsCode; // 80 30 518523
$faker->invalidPtsCode; // 67ОМ3760020
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->stsCode; // 98РА409963
$faker->invalidStsCode; // 47 77 6580290
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->vinCode; // LPFT634A62NV25411
$faker->invalidVinCode; // 728GY9PAGGSH443220
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->driverLicenseNumber; // 66 ВС 167633
$faker->invalidDriverLicenseNumber; // 6802О3
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->innCode(); // 6449013711 500100732259
$faker->shortInnCode(); // 3664069397
$faker->longInnCode(); // 500100732259
$faker->validInnCode(); // 6449013711
$faker->invalidInnCode(); // 6449013712
$faker->kppCode(); // 644901371
$faker->validKppCode(); // 773301001 7733AZ001
$faker->invalidKppCode(); // 7733010011 77330100Z
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->cadastralNumber(); // 66:41:153222:68
$faker->validCadastralNumber(); // 77:22:5874698:1
$faker->invalidCadastralNumber(); // 879:404:313:446
Package avto-dev/identity-laravel is required for this.
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->idEntity('VIN'); // object:TypedIDEntityInterface (type 'VIN')
$faker->idEntity; // object:TypedIDEntityInterface (random type)
<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */
$faker->userAvatarUri('Bill Gates', 200, 200); // Link to the some user avatar
Examples:
For package testing we use phpunit
framework and docker-ce
+ docker-compose
as develop environment. So, just write into your terminal after repository cloning:
$ make build
$ make latest # or 'make lowest'
$ make test
Changes log can be found here.
If you will find any package errors, please, make an issue in current repository.
This is open-sourced software licensed under the MIT License.