PHPackages                             icanhazstring/phpunit-faker-extension - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. icanhazstring/phpunit-faker-extension

ActiveLibrary[Testing &amp; Quality](/categories/testing)

icanhazstring/phpunit-faker-extension
=====================================

PHPUnit extension to add faker support

0.1(7y ago)511.2k↓22.2%MITPHPPHP ^7.1

Since Jan 25Pushed 7y ago1 watchersCompare

[ Source](https://github.com/icanhazstring/phpunit-faker-extension)[ Packagist](https://packagist.org/packages/icanhazstring/phpunit-faker-extension)[ RSS](/packages/icanhazstring-phpunit-faker-extension/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (0)

phpunit-faker-extension
=======================

[](#phpunit-faker-extension)

[![Build](https://camo.githubusercontent.com/84f17ef43216679bc76901d421663fd3495989882316b6348c02cb7f6ac6c8ed/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6963616e68617a737472696e672f706870756e69742d66616b65722d657874656e73696f6e2f6d61737465722e737667)](https://camo.githubusercontent.com/84f17ef43216679bc76901d421663fd3495989882316b6348c02cb7f6ac6c8ed/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f6963616e68617a737472696e672f706870756e69742d66616b65722d657874656e73696f6e2f6d61737465722e737667)[![Min php version](https://camo.githubusercontent.com/a249b207575a97af6869597ddd351506646e23e39d9b1ba745e9a8f5e8b89d4f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e312d6c69676874677265792e737667)](https://camo.githubusercontent.com/a249b207575a97af6869597ddd351506646e23e39d9b1ba745e9a8f5e8b89d4f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545372e312d6c69676874677265792e737667)[![Min phpunit version](https://camo.githubusercontent.com/cddcd6c990c7d0a24d121f90d2af7e7fff7555ff3f447beb1333780974d199bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706870756e6974253246706870756e69742d253545372e352d6c69676874677265792e737667)](https://camo.githubusercontent.com/cddcd6c990c7d0a24d121f90d2af7e7fff7555ff3f447beb1333780974d199bd/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f706870756e6974253246706870756e69742d253545372e352d6c69676874677265792e737667)

Using this extension you can use [fzaninotto/faker](https://github.com/fzaninotto/faker) with your phpunit tests. Every test will be seeded so you will be able run the same test again if an error occurs.

[![phpunit-faker-extension-screenshot](https://camo.githubusercontent.com/e6933cdd41861dee1ebbeab2723a7b83a56d6f8777c465c86c0abd581071f5d9/68747470733a2f2f692e696d6775722e636f6d2f3561595539684a2e706e67)](https://camo.githubusercontent.com/e6933cdd41861dee1ebbeab2723a7b83a56d6f8777c465c86c0abd581071f5d9/68747470733a2f2f692e696d6775722e636f6d2f3561595539684a2e706e67)

Installation
------------

[](#installation)

You can install this extension by using [Composer](http://getcomposer.org). This package should be added as a `require-dev` dependency:

```
composer require --dev icanhazstring/phpunit-faker-extension

```

Usage
-----

[](#usage)

Enable with all defaults by adding the following code to your project's `phpunit.xml` file:

```

...

```

Now run the test suite as normal. As soon as all tests are completed, you will see a seed that was used to generate the faker data:

`Tests done with seed: XXX`

### Using Fake inside a test

[](#using-fake-inside-a-test)

To use faker inside your tests, you will need to implement the `FakerAwareTest` interface and the `FakerTrait`. Since not all tests will need faker, the interface makes sure only tests using faker, will get the needed data.

To actually invoke you only need to do the following:

```
class AwesomeTest extends TestCase implements FakerAwareTest
{
    use FakerTrait;

    public function testAwesomeStuff(): void
    {
        $this->assertSame($this->fake()->name, $this->fake()->name);
    }
}
```

> See faker documentation for more information about formatters:

### Running tests with a given seed

[](#running-tests-with-a-given-seed)

To run tests with a given seed, simple set the `PHPUNIT_SEED` environment variable before running phpunit:

```
$ PHPUNIT_SEED=XXX vendor/bin/phpunit
```

Configuration
-------------

[](#configuration)

This extension has three configurable parameters:

- **locale** - The locale that faker should use (Default: `en_GB`)
- **fakerProviderProvider** - (Silly name I know) A single invokable class returning a list of providers (string or instance)

These configuration parameters are set in `phpunit.xml` when adding the listener:

```

                        de_DE

                        Your\FakerProviderProvider

```

License
-------

[](#license)

phpunit-faker-extension is available under the MIT License.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2660d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd1997b796c59d155bbaedeffafd15f61ab16f2d469824d77859e9918931de47?d=identicon)[icanhazstring](/maintainers/icanhazstring)

---

Top Contributors

[![icanhazstring](https://avatars.githubusercontent.com/u/883543?v=4)](https://github.com/icanhazstring "icanhazstring (7 commits)")

---

Tags

extensionfakerphpunittesting

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/icanhazstring-phpunit-faker-extension/health.svg)

```
[![Health](https://phpackages.com/badges/icanhazstring-phpunit-faker-extension/health.svg)](https://phpackages.com/packages/icanhazstring-phpunit-faker-extension)
```

###  Alternatives

[timacdonald/log-fake

A drop in fake logger for testing with the Laravel framework.

4235.9M54](/packages/timacdonald-log-fake)[jasonmccreary/laravel-test-assertions

A set of helpful assertions when testing Laravel applications.

3513.9M31](/packages/jasonmccreary-laravel-test-assertions)[ergebnis/phpunit-slow-test-detector

Provides facilities for detecting slow tests in phpunit/phpunit.

1468.1M72](/packages/ergebnis-phpunit-slow-test-detector)[typo3/testing-framework

The TYPO3 testing framework provides base classes for unit, functional and acceptance testing.

675.0M772](/packages/typo3-testing-framework)[robiningelbrecht/phpunit-pretty-print

Prettify PHPUnit output

76460.0k15](/packages/robiningelbrecht-phpunit-pretty-print)[webmozarts/strict-phpunit

Enables type-safe comparisons of objects in PHPUnit

31252.7k5](/packages/webmozarts-strict-phpunit)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
