avto-dev/faker-providers

Extended faker package providers

v3.8.0 2024-08-23 10:53 UTC

This package is auto-updated.

Last update: 2024-10-23 11:19:33 UTC


README

Laravel

Additional providers for fakerphp/faker

Version PHP Version Build Status Coverage Downloads count License

This package provides set of additional providers for faker package. Also it provides service-provider for Laravel framework.

Install

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.

Laravel integration

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.

Usage

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

Providers

All providers located in AvtoDev\FakerProviders\Providers namespace.

Cars\MarkAndModelProvider

<?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

Identifiers\BodyProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->bodyCode;        // ILМ842 6262494
$faker->invalidBodyCode; // 246553

Identifiers\ChassisProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->chassisCode;        // СM3654637018
$faker->invalidChassisCode; // 20567820000000000

Identifiers\GrzProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->grzCode;        // Х133АМ02
$faker->invalidGrzCode; // У777

Identifiers\PtsProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->ptsCode;        // 80 30 518523
$faker->invalidPtsCode; // 67ОМ3760020

Identifiers\StsProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->stsCode;        // 98РА409963
$faker->invalidStsCode; // 47 77 6580290

Identifiers\VinProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->vinCode;        // LPFT634A62NV25411
$faker->invalidVinCode; // 728GY9PAGGSH443220

Identifiers\DriverLicenseNumberProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->driverLicenseNumber;        // 66 ВС 167633
$faker->invalidDriverLicenseNumber; // 6802О3

Identifiers\InnAndKppProvider

<?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

Identifiers\CadastralNumberProvider

<?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

Packages\IDEntityProvider

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)

User\AvatarUriProvider

<?php /** @var \Faker\Generator|\AvtoDev\FakerProviders\ExtendedFaker $faker */

$faker->userAvatarUri('Bill Gates', 200, 200); // Link to the some user avatar

Examples:

Testing

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

Release date Commits since latest release

Changes log can be found here.

Support

Issues Issues

If you will find any package errors, please, make an issue in current repository.

License

This is open-sourced software licensed under the MIT License.