Faker is a PHP library that generates fake data for you

Related tags

Testing Faker
Overview

Social card of FakerPHP

Faker

Packagist Downloads GitHub Workflow Status Type Coverage Code Coverage

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.1.

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
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();
// '[email protected]'
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
for ($i = 0; $i < 3; $i++) {
    echo $faker->name() . "\n";
}

// 'Cyrus Boyle'
// 'Alena Cummerata'
// 'Orlo Bergstrom'

License

Faker is released under the MIT License. See LICENSE for details.

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.

Comments
  • French: added translated color for french language

    French: added translated color for french language

    What is the reason for this PR?

    • [x] A new feature
    • [ ] Fixed an issue (resolve #ID)

    Author's checklist

    Summary of changes

    I simply added a list of colors we use in french.

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    opened by RSickenberg 29
  • Feature request: minimum character count for realText

    Feature request: minimum character count for realText

    I recently wrote a simple loop to ensure realText() would provide a minimum character count. It would be nice if this could be added as a parameter to the method itself instead. I'm more than happy to PR this in, and will likely do so over the weekend.

    enhancement 
    opened by FatBoyXPC 27
  • Make Doctrine populator compatible with newer versions of Doctrine

    Make Doctrine populator compatible with newer versions of Doctrine

    What is the reason for this PR?

    As described in https://github.com/FakerPHP/Faker/issues/149 Doctrine changed some of it's namespaces recently. This change will make the code work with both the new and the old namespace.

    • [X] Fixed an issue (resolve #149)

    Author's checklist

    Summary of changes

    Adding namespace checks to make the code compatible with both Doctrine 2.7 and Doctrine 2.8+

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    pinned 
    opened by jlHertel 18
  • Ensure php 8.2 compatibility

    Ensure php 8.2 compatibility

    This PR makes sure that the current state and future changes are tested against php 8.2.

    I fixed two unit tests which fail in php 8.2 only, since php introduced a new random extension. Even without this change to the extension, I think the tests make more sense now.

    As you can tell when executing the Faker tests in a php 8.2 environment, the following new deprecation's occur:

    Remaining self deprecation notices (605)
    
      404x: Use of "static" in callables is deprecated
        200x in PhoneNumberTest::testPhoneNumber from Faker\Test\Provider\de_DE
        200x in PhoneNumberTest::testE164PhoneNumberFormat from Faker\Test\Provider\de_DE
        4x in PaymentTest::testBankAccountNumber from Faker\Test\Provider\ne_NP
    
      201x: Use of "self" in callables is deprecated
        134x in IbanTest::testIsValid from Faker\Test\Calculator
        67x in IbanTest::testChecksum from Faker\Test\Calculator
    

    All of those are caused by legacy Faker components that probably cannot be fixed without making a backward incompatible change (related PHP RFC). I think it makes more sense to refactor all affected areas to the new Faker structure in order to be compatible to php 9.0.

    Since we can't refactor everything right now, I've configured phpunit-bridge to not report a failed test execution unless we reach more than 1000 deprecation errors (we have 605 right now).

    enhancement pinned 
    opened by chris-doehring 17
  • Fix for support on different Doctrine ORM versions

    Fix for support on different Doctrine ORM versions

    Add conflict to doctrine/persistence below 1.4 and use correct persistence classes

    What is the reason for this PR?

    Fix an issue with doctrine/persistnce

    • [x] Fixed an issue (resolve #413 )

    Author's checklist

    Summary of changes

    • ~Add a conflict into composer.json for doctrine/persistence below version 1.4~
    • Add suggest into composer.json for doctrine/orm
    • ~Add doctrine/orm as dev requirement to avoid static analysis baseline entries~
    • ~Use new classes of doctrine/orm and doctrine/persistence for Faker\ORM\Doctrine namespace~
    • Add class_alias for ClassMetadata and ObjectManager

    Review checklist

    • [x] All checks have passed
    • [ ] Changes are approved by maintainer
    opened by icanhazstring 17
  • `Base::unique` contains null while type says it does not

    `Base::unique` contains null while type says it does not

    Summary

    Base::unique property is not initialized in constructor and its type does not allow null value.

    Though, the null value is there so the type is wrong and it's a bug.

    Versions

    | | Version | |:---------------|:--------| | fakerphp/faker | 1.y.z |

    Self-enclosed code snippet for reproduction

    See https://github.com/FakerPHP/Faker/pull/309 on how to fix the bug

    opened by simPod 17
  • Faker->image() return 0 on windows local env

    Faker->image() return 0 on windows local env

    Versions

    | Module/Lib | Version | |:---------------|:--------| | PHP | 8.1.5 | | fakerphp/faker | 1.19.0 | | Laravel | 9.10.0 |

    Faker->image() return 0 on windows local env, but it works with adding at Faker\Provider\Image after string 114:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    

    Is this a safe solution?

    wontfix 
    opened by FFomaXX 15
  • Add used extensions to composer.json

    Add used extensions to composer.json

    What is the reason for this PR?

    Faker uses a couple of php extensions that are not included in composer.json's require.

    • [ ] A new feature
    • [ ] Fixed an issue (resolve #ID)

    Author's checklist

    Summary of changes

    This PR adds the required extensions:

    • ext-dom is used e.g. in https://github.com/FakerPHP/Faker/blob/9f12db8c85c5d10ec1ca02be7097aabd5e1ee67c/src/Faker/Provider/HtmlLorem.php#L50

    • ext-iconv is used in https://github.com/FakerPHP/Faker/blob/9f12db8c85c5d10ec1ca02be7097aabd5e1ee67c/src/Faker/Provider/ru_RU/Text.php#L11

    • ext-json is used in https://github.com/FakerPHP/Faker/blob/9f12db8c85c5d10ec1ca02be7097aabd5e1ee67c/src/Faker/Provider/Miscellaneous.php#L321

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    bug 
    opened by krsriq 14
  • Updated the generator phpdoc to help identifier magic methods

    Updated the generator phpdoc to help identifier magic methods

    What is the reason for this PR?

    As mentioned in #303 there are some problems with static code analysis for our deprecation warnings in 1.14. With this PR i did some reflection and generated a new PHPDoc to match the actual code itself

    • [ ] A new feature
    • [ ] Fixed an issue (resolve #ID)

    Author's checklist

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    needs work 
    opened by pimjansen 13
  • [es_PE] Add common first and last names

    [es_PE] Add common first and last names

    What is the reason for this PR?

    • [x] A new feature
    • [ ] Fixed an issue (resolve #ID)

    Author's checklist

    Summary of changes

    Add names and Last Name common at Perú

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    enhancement invalid 
    opened by Oxicode 13
  • Enhancement: Use friendsofphp/php-cs-fixer instead of StyleCI

    Enhancement: Use friendsofphp/php-cs-fixer instead of StyleCI

    This PR

    • [x] requires friendsof/php-cs-fixer and removes the integration with StyleCI

    StyleCI

    The integration with StyleCI has the following advantages:

    • It applies coding standard issues automatically after a merge to main.

    The integration with StyleCI has the following disadvantages:

    • ~~A developer can not run StyleCI locally.~~ A developer can run StyleCI locally only by installing a separate package, which however, requires PHP 7.2. We currently support PHP 7.1.
    • If a developer wants to find out about the changes that would need to be applied, they have to navigate to a separate website. With the deep integration provided by GitHub Actions, that is not necessary anymore.
    • StyleCI uses friendsofphp/php-cs-fixer under the hood, but adds obscurity on top. For example, it "invents" new fixers that can be enabled or enabled, but are in reality different configurations for existing fixers). Additionally, fixers that are available today in friendsofphp/php-cs-fixer cannot be configured in StyleCI without delay (if at all). Furthermore, we do not know which version of friendsofphp/php-cs-fixer is used under the hood.
    • The integration with StyleCI violates the principle of least astonishment: When someone opens a pull request where the changes do not conform to the coding standard we configured, a reviewer can (and will be) surprised to see that the build passes. A reviewer might similarly (and rightfully) point out coding standard issues, which adds unnecessary noise to the conversation in a pull request.

    friendsofphp/php-cs-fixer

    Requiring friendsofphp/php-cs-fixer as a dependency (similar to phpstan/phpstan and vimeo/psalm) alleviates all of these problems. We can use and configure any fixers that is available any time we want.

    If we wanted to automatically apply coding standard issues (similar to StyleCI), we could easily do that with GitHub Actions. However, I would suggest to refrain from it.

    In my opinion, a pull request needs to be in mergeable state before merging it into the mainline of development, and this includes coding standard issues.

    enhancement 
    opened by localheinz 13
  • Removed the name Adolf and similarities

    Removed the name Adolf and similarities

    What is the reason for this PR?

    In a few data sets, there was a name Adolf, Adolph or something similar. It is not appropriate to give the name Adolph to a person, as it is associated with Adolf Hitler, who was the leader of Nazi Germany during World War II and responsible for the deaths of millions of people, including six million Jews. The use of this name would be offensive and inappropriate, as it is associated with one of the most heinous regimes in history.

    This fix is especially useful for people who use this database for seeding test data what will be seen by management and possible customers. This wil avoid misunderstandings.

    • [ ] A new feature
    • [x] Fixed an issue (resolve #ID)

    Author's checklist

    Summary of changes

    See upper paragraph

    Review checklist

    • [x] All checks have passed
    • [ ] Changes are approved by maintainer
    opened by Joas707 2
  • Doctrine ObjectManager namespace has changed

    Doctrine ObjectManager namespace has changed

    Summary

    In the last version of Doctrine (2.13), ObjectManager namespace has changed from: Doctrine\Common\Persistence\ObjectManager

    To:

    Doctrine\Persistence\ObjectManager

    Versions

    | | Version | |:---------------|:--------| | PHP | 8.1.2 | | fakerphp/faker | 1.21.0 |

    Possible solutions

    Remplace namespace on Faker\ORM\Doctrine\Populator

    invalid 
    opened by ElMulot 3
  • fixed typo and append a lack japanese lastkananames

    fixed typo and append a lack japanese lastkananames

    What is the reason for this PR?

    • [ ] A new feature
    • [x] Fixed an issue (resolve #ID)

    Author's checklist

    Summary of changes

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    opened by maryco 0
  • Fix: Install required extensions only

    Fix: Install required extensions only

    What is the reason for this PR?

    • [x] install required extensions only

    Author's checklist

    Summary of changes

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    bug lifecycle/stale 
    opened by localheinz 3
  • Ensure French department number to be return as string

    Ensure French department number to be return as string

    What is the reason for this PR?

    • [ ] A new feature
    • [x] Fixed an issue (resolve #391 )

    Author's checklist

    Summary of changes

    Reversal of the department name and number so that the latter is always returned as a string

    Review checklist

    • [ ] All checks have passed
    • [ ] Changes are approved by maintainer
    lifecycle/stale 
    opened by ker0x 3
Releases(v1.21.0)
  • v1.21.0(Dec 13, 2022)

  • v1.20.0(Jul 20, 2022)

    • Fixed typo in French phone number (#452)
    • Fixed some Hungarian naming bugs (#451)
    • Fixed bug where the NL-BE VAT generation was incorrect (#455)
    • Improve Turkish phone numbers for E164 and added landline support (#460)
    • Add Microsoft Edge User Agent (#464)
    • Added option to set image formats on Faker\Provider\Image (#473)
    • Added support for French color translations (#466)
    • Support filtering timezones by country code (#480)
    • Fixed typo in some greek names (#490)
    • Marked the Faker\Provider\Image as deprecated
    Source code(tar.gz)
    Source code(zip)
  • v1.19.0(Feb 2, 2022)

    • Added color extension to core (#442)
    • Added conflict with doctrine/persistence below version 1.4
    • Fix for support on different Doctrine ORM versions (#414)
    • Fix usage of Doctrine\Persistence dependency
    • Fix CZ Person birthNumber docblock return type (#437)
    • Fix is_IS Person docbock types (#439)
    • Fix is_IS Address docbock type (#438)
    • Fix regexify escape backslash in character class (#434)
    • Removed UUID from Generator to be able to extend it (#441)
    Source code(tar.gz)
    Source code(zip)
  • v1.18.0(Jan 23, 2022)

    • Deprecated UUID, use uuid3 to specify version (#427)
    • Reset formatters when adding a new provider (#366)
    • Helper methods to use our custom generators (#155)
    • Set allow-plugins for Composer 2.2 (#405)
    • Fix kk_KZ\Person::individualIdentificationNumber generation (#411)
    • Allow for -> syntax to be used in parsing (#423)
    • Person->name was missing string return type (#424)
    • Generate a valid BE TAX number (#415)
    • Added the UUID extension to Core (#427)
    Source code(tar.gz)
    Source code(zip)
  • v1.17.0(Dec 5, 2021)

    • Partial PHP 8.1 compatibility (#373)
    • Add payment provider for ne_NP locale (#375)
    • Add Egyptian Arabic ar_EG locale (#377)
    • Updated list of South African TLDs (#383)
    • Fixed formatting of E.164 numbers (#380)
    • Allow symfony/deprecation-contracts ^3.0 (#397)
    Source code(tar.gz)
    Source code(zip)
  • v1.16.0(Sep 6, 2021)

    • Add Company extension
    • Add Address extension
    • Add Person extension
    • Add PhoneNumber extension
    • Add VersionExtension (#350)
    • Stricter types in Extension\Container and Extension\GeneratorAwareExtension (#345)
    • Fix deprecated property access in nl_NL (#348)
    • Add support for psr/container >= 2.0 (#354)
    • Add missing union types in Faker\Generator (#352)
    Source code(tar.gz)
    Source code(zip)
  • v1.15.0(Jul 6, 2021)

    • Updated the generator phpdoc to help identify magic methods (#307)
    • Prevent direct access and triggered deprecation warning for "word" (#302)
    • Updated length on all global e164 numbers (#301)
    • Updated last names from different source (#312)
    • Don't generate birth number of '000' for Swedish personal identity (#306)
    • Add job list for localization id_ID (#339)
    Source code(tar.gz)
    Source code(zip)
  • v1.14.1(Mar 30, 2021)

  • v1.14.0(Mar 29, 2021)

    • Fix for realText to ensure the text keeps closer to its boundaries (#152)

    • Fix where regexify produces a random character instead of a literal dot (#135

    • Deprecate zh_TW methods that only call base methods (#122)

    • Add used extensions to composer.json as suggestion (#120)

    • Moved TCNo and INN from calculator to localized providers (#108)

    • Fix regex dot/backslash issue where a dot is replaced with a backslash as escape character (#206)

    • Deprecate direct property access (#164)

    • Added test to assert unique() behaviour (#233)

    • Added RUC for the es_PE locale (#244)

    • Test IBAN formats for Latin America (AR/PE/VE) (#260)

    • Added VAT number for en_GB (#255)

    • Added new districts for the ne_NP locale (#258)

    • Fix for U.S. Area Code Generation (#261)

    • Fix in numerify where a better random numeric value is guaranteed (#256)

    • Fix e164PhoneNumber to only generate valid phone numbers with valid country codes (#264)

    • Extract fixtures into separate classes (#234)

    • Remove french domains that no longer exists (#277)

    • Fix error that occurs when getting a polish title (#279)

    • Use valid area codes for North America E164 phone numbers (#280)

    • Adding support for extensions and PSR-11 (#154)

    • Adding trait for GeneratorAwareExtension (#165)

    • Added helper class for extension (#162)

    • Added blood extension to core (#232)

    • Added barcode extension to core (#252)

    • Added number extension (#257)

    • Various code style updates

    • Added a note about our breaking change promise (#273)

    Source code(tar.gz)
    Source code(zip)
  • v1.13.0(Dec 18, 2020)

    Several fixes and new additions in this release. A lot of cleanup has been done on the codebase on both tests and consistency.

    • Feature/pl pl license plate (#62)
    • Fix greek phone numbers (#16)
    • Move AT payment provider logic to de_AT (#72)
    • Fix wiktionary links (#73)
    • Fix AT person links (#74)
    • Fix AT cities (#75)
    • Deprecate at_AT providers (#78)
    • Add Austrian ssn() to Person provider (#79)
    • Fix typos in id_ID Address (#83)
    • Austrian post codes (#86)
    • Updated Polish data (#70)
    • Improve Austrian social security number generation (#88)
    • Move US phone numbers with extension to own method (#91)
    • Add UK National Insurance number generator (#89)
    • Fix en_SG phone number generator (#100)
    • Remove usage of mt_rand (#87)
    • Remove whitespace from beginning of el_GR phone numbers (#105)
    • Building numbers can not be 0, 00, 000 (#107)
    • Add 172.16/12 local IPv4 block (#121)
    • Add JCB credit card type (#124)
    • Remove json_decode from emoji generation (#123)
    • Remove ro street address (#146)
    Source code(tar.gz)
    Source code(zip)
  • v1.12.1(Dec 11, 2020)

  • v1.9.2(Dec 11, 2020)

  • v1.12.0(Nov 23, 2020)

    • Added Singapore NRIC/FIN provider (#56)
    • Added provider for Lithuanian municipalities (#58)
    • Added blood types provider (#61)
    • Fix ro_RO first and last day of year calculation offset (#65)
    • Fix en_NG locale test namespaces that did not match PSR-4 (#57)
    Source code(tar.gz)
    Source code(zip)
  • v1.11.0(Nov 15, 2020)

  • v1.10.1(Oct 28, 2020)

    • Updates the Danish addresses in dk_DK
    • Removed offense company names in nl_NL
    • Clarify changelog with original fork
    • Standin replacement for LoremPixel to Placeholder.com (#11)
    Source code(tar.gz)
    Source code(zip)
  • v1.10.0(Oct 27, 2020)

    • Support PHP 7.1-8.0
    • Fix typo in de_DE Company Provider
    • Fix dateTimeThisYear method
    • Fix typo in de_DE jobTitleFormat
    • Fix IBAN generation for CR
    • Fix typos in greek first names
    • Fix US job title typo
    • Do not clear entity manager for doctrine orm populator
    • Remove persian rude words
    • Corrections to RU names
    Source code(tar.gz)
    Source code(zip)
  • v1.9.1(Oct 27, 2020)

Owner
FakerPHP
The new home for Faker PHP
FakerPHP
Allows DataObjects to self-populate intelligently with fake data

Mock DataObjects for SilverStripe This module provides intelligent content generation functionality to all DataObjects. The object introspects its fie

Aaron Carlino 18 Oct 29, 2017
A drop in fake logger for testing with the Laravel framework.

Log fake for Laravel A bunch of Laravel facades / services are able to be faked, such as the Dispatcher with Bus::fake(), to help with testing and ass

Tim MacDonald 363 Dec 19, 2022
PHP Test Generator - A CLI tool which generates unit tests

This project make usages of PHPStan and PHPParser to generate test cases for a given PHP File.

Alexander Schranz 7 Dec 3, 2022
Provides generic data providers for use with phpunit/phpunit.

data-provider Installation Run composer require --dev ergebnis/data-provider Usage This package provides the following generic data providers: Ergebni

null 25 Jan 2, 2023
TestDummy makes the process of preparing factories (dummy data) for your integration tests as easy as possible

TestDummy TestDummy makes the process of preparing factories (dummy data) for your integration tests as easy as possible. As easy as... Build a Post m

Laracasts 461 Sep 28, 2022
Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slowness of constantly restarting the testing environment.

Magic Test for Laravel Magic Test allows you to write browser tests by simply clicking around on the application being tested, all without the slownes

null 400 Jan 5, 2023
Library that provides collection, processing, and rendering functionality for PHP code coverage information.

phpunit/php-code-coverage Provides collection, processing, and rendering functionality for PHP code coverage information. Installation You can add thi

Sebastian Bergmann 8.5k Jan 5, 2023
A PHP library for mocking date and time in tests

ClockMock Slope s.r.l. ClockMock provides a way for mocking the current timestamp used by PHP for \DateTime(Immutable) objects and date/time related f

Slope 44 Dec 7, 2022
PHPArch is a work in progress architectural testing library for PHP projects

PHPArch What is this? Installation Simple Namespace validation Available Validators Defining an architecture Syntactic sugar: Bulk definition of compo

Johannes Hertenstein 236 Nov 28, 2022
Mockery - Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library

Mockery Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its c

Mockery 10.3k Jan 1, 2023
PHP client for Selenium/WebDriver protocol. Previously facebook/php-webdriver

Php-webdriver library is PHP language binding for Selenium WebDriver, which allows you to control web browsers from PHP.

php-webdriver 4.7k Jan 3, 2023
The modern, simple and intuitive PHP unit testing framework.

atoum PHP version atoum version 5.3 -> 5.6 1.x -> 3.x 7.2 -> 8.x 4.x (current) A simple, modern and intuitive unit testing framework for PHP! Just lik

atoum 1.4k Nov 29, 2022
Full-stack testing PHP framework

Codeception Modern PHP Testing for everyone Codeception is a modern full-stack testing framework for PHP. Inspired by BDD, it provides an absolutely n

Codeception Testing Framework 4.6k Jan 7, 2023
Mock HTTP requests on the server side in your PHP unit tests

HTTP Mock for PHP Mock HTTP requests on the server side in your PHP unit tests. HTTP Mock for PHP mocks the server side of an HTTP request to allow in

InterNations GmbH 386 Dec 27, 2022
AST based PHP Mutation Testing Framework

Infection - Mutation Testing framework Please read documentation here: infection.github.io Twitter: @infection_php Discord: https://discord.gg/ZUmyHTJ

Infection - Mutation Testing Framework for PHP 1.8k Jan 2, 2023
:heavy_check_mark: PHP Test Framework for Freedom, Truth, and Justice

Kahlan is a full-featured Unit & BDD test framework a la RSpec/JSpec which uses a describe-it syntax and moves testing in PHP one step forward. Kahlan

Kahlan 1.1k Jan 2, 2023
Event driven BDD test framework for PHP

The highly extensible, highly enjoyable, PHP testing framework. Read more at peridot-php.github.io or head over to the wiki. Building PHAR Peridot's p

Peridot 327 Jan 5, 2023
PHP Mocking Framework

Phake Phake is a framework for PHP that aims to provide mock objects, test doubles and method stubs. Phake was inspired by a lack of flexibility and e

Phake 469 Dec 2, 2022