You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.9 KiB

3 years ago
  1. <p style="text-align: center"><img src="https://github.com/FakerPHP/Artwork/raw/main/src/socialcard.png" alt="Social card of FakerPHP"></p>
  2. # Faker
  3. [![Packagist Downloads](https://img.shields.io/packagist/dm/FakerPHP/Faker)](https://packagist.org/packages/fakerphp/faker)
  4. [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/FakerPHP/Faker/Tests/main)](https://github.com/FakerPHP/Faker/actions)
  5. [![Type Coverage](https://shepherd.dev/github/FakerPHP/Faker/coverage.svg)](https://shepherd.dev/github/FakerPHP/Faker)
  6. [![Code Coverage](https://codecov.io/gh/FakerPHP/Faker/branch/main/graph/badge.svg)](https://codecov.io/gh/FakerPHP/Faker)
  7. 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.
  8. It's heavily inspired by Perl's [Data::Faker](https://metacpan.org/pod/Data::Faker), and by Ruby's [Faker](https://rubygems.org/gems/faker).
  9. ## Getting Started
  10. ### Installation
  11. Faker requires PHP >= 7.1.
  12. ```shell
  13. composer require fakerphp/faker
  14. ```
  15. ### Documentation
  16. Full documentation can be found over on [fakerphp.github.io](https://fakerphp.github.io).
  17. ### Basic Usage
  18. 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.
  19. ```php
  20. <?php
  21. require_once 'vendor/autoload.php';
  22. // use the factory to create a Faker\Generator instance
  23. $faker = Faker\Factory::create();
  24. // generate data by calling methods
  25. echo $faker->name();
  26. // 'Vince Sporer'
  27. echo $faker->email();
  28. // 'walter.sophia@hotmail.com'
  29. echo $faker->text();
  30. // 'Numquam ut mollitia at consequuntur inventore dolorem.'
  31. ```
  32. 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)`.
  33. ```php
  34. <?php
  35. for ($i = 0; $i < 3; $i++) {
  36. echo $faker->name() . "\n";
  37. }
  38. // 'Cyrus Boyle'
  39. // 'Alena Cummerata'
  40. // 'Orlo Bergstrom'
  41. ```
  42. ## License
  43. Faker is released under the MIT License. See [`LICENSE`](LICENSE) for details.
  44. ## Backward compatibility promise
  45. Faker is using [Semver](https://semver.org/). This means that versions are tagged
  46. with MAJOR.MINOR.PATCH. Only a new major version will be allowed to break backward
  47. compatibility (BC).
  48. Classes marked as `@experimental` or `@internal` are not included in our backward compatibility promise.
  49. You are also not guaranteed that the value returned from a method is always the
  50. same. You are guaranteed that the data type will not change.
  51. PHP 8 introduced [named arguments](https://wiki.php.net/rfc/named_params), which
  52. increased the cost and reduces flexibility for package maintainers. The names of the
  53. arguments for methods in Faker is not included in our BC promise.