fakerphp / faker
Faker is a PHP library that generates fake data for you.
Installs: 224 040 182
Dependents: 2 701
Suggesters: 49
Security: 0
Stars: 3 616
Watchers: 25
Forks: 3 588
Open Issues: 43
Requires
- php: ^7.4 || ^8.0
- psr/container: ^1.0 || ^2.0
- symfony/deprecation-contracts: ^2.2 || ^3.0
Requires (Dev)
- ext-intl: *
- bamarni/composer-bin-plugin: ^1.4.1
- doctrine/persistence: ^1.3 || ^2.0
- phpunit/phpunit: ^9.5.26
- symfony/phpunit-bridge: ^5.4.16
Suggests
- ext-curl: Required by Faker\Provider\Image to download images.
- ext-dom: Required by Faker\Provider\HtmlLorem for generating random HTML.
- ext-iconv: Required by Faker\Provider\ru_RU\Text::realText() for generating real Russian text.
- ext-mbstring: Required for multibyte Unicode string functionality.
- doctrine/orm: Required to use Faker\ORM\Doctrine
Conflicts
- 2.0.x-dev
- 1.24.x-dev
- v1.24.1
- v1.24.0
- v1.23.1
- v1.23.0
- v1.22.0
- v1.21.0
- v1.20.0
- v1.19.0
- v1.18.0
- v1.17.0
- v1.16.0
- v1.15.0
- v1.14.1
- v1.14.0
- v1.13.0
- v1.12.1
- v1.12.0
- 1.11.3
- 1.11.2
- 1.11.1
- v1.11.0
- v1.10.1
- v1.10.0
- v1.9.2
- v1.9.1
- v1.9.0
- v1.8.0
- v1.7.1
- v1.7.0
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.0
- v1.0.0
- dev-dependabot/composer/vendor-bin/rector/rector/rector-1.0.3
- dev-dependabot/composer/vendor-bin/psalm/vimeo/psalm-5.23.1
- dev-dependabot/composer/vendor-bin/phpstan/phpstan/phpstan-1.10.66
- dev-dependabot/composer/vendor-bin/php-cs-fixer/friendsofphp/php-cs-fixer-3.52.1
- dev-dependabot/github_actions/actions/cache-4
This package is auto-updated.
Last update: 2024-11-21 13:47:18 UTC
README
Faker
Faker is a PHP library that generates fake data for you. Whether you need to bootstrap your database, create good-looking XML documents, fill-in your persistence to stress test it, or anonymize data taken from a production service, Faker is for you.
It's heavily inspired by Perl's Data::Faker, and by Ruby's Faker.
Getting Started
Installation
Faker requires PHP >= 7.4.
composer require fakerphp/faker
Documentation
Full documentation can be found over on fakerphp.github.io.
Basic Usage
Use Faker\Factory::create()
to create and initialize a Faker generator, which can generate data by accessing methods named after the type of data you want.
<?php declare(strict_types=1); require_once 'vendor/autoload.php'; // use the factory to create a Faker\Generator instance $faker = Faker\Factory::create(); // generate data by calling methods echo $faker->name(); // 'Vince Sporer' echo $faker->email(); // 'walter.sophia@hotmail.com' echo $faker->text(); // 'Numquam ut mollitia at consequuntur inventore dolorem.'
Each call to $faker->name()
yields a different (random) result. This is because Faker uses __call()
magic, and forwards Faker\Generator->$method()
calls to Faker\Generator->format($method, $attributes)
.
<?php declare(strict_types=1); for ($i = 0; $i < 3; $i++) { echo $faker->name() . "\n"; } // 'Cyrus Boyle' // 'Alena Cummerata' // 'Orlo Bergstrom'
Automated refactoring
If you already used this library with its properties, they are now deprecated and needs to be replaced by their equivalent methods.
You can use the provided Rector config file to automate the work.
Run
composer require --dev rector/rector
to install rector/rector
.
Run
vendor/bin/rector process src/ --config vendor/fakerphp/faker/rector-migrate.php
to run rector/rector
.
Note: do not forget to replace src/
with the path to your source directory.
Alternatively, import the configuration in your rector.php
file:
<?php declare(strict_types=1); use Rector\Config; return static function (Config\RectorConfig $rectorConfig): void { $rectorConfig->import('vendor/fakerphp/faker/rector-migrate.php'); };
License
Faker is released under the MIT License. See LICENSE
for details.
PHP Version Support Policy
The maintainers of this package add support for a PHP version following its initial release and drop support for a PHP version one year after it has reached its end of security support.
Backward compatibility promise
Faker is using Semver. This means that versions are tagged with MAJOR.MINOR.PATCH. Only a new major version will be allowed to break backward compatibility (BC).
Classes marked as @experimental
or @internal
are not included in our backward compatibility promise.
You are also not guaranteed that the value returned from a method is always the
same. You are guaranteed that the data type will not change.
PHP 8 introduced named arguments, which increased the cost and reduces flexibility for package maintainers. The names of the arguments for methods in Faker is not included in our BC promise.