Download the PHP package icanhazstring/phpunit-faker-extension without Composer
On this page you can find all versions of the php package icanhazstring/phpunit-faker-extension. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download icanhazstring/phpunit-faker-extension
More information about icanhazstring/phpunit-faker-extension
Files in icanhazstring/phpunit-faker-extension
Package phpunit-faker-extension
Short Description PHPUnit extension to add faker support
License MIT
Informations about the package phpunit-faker-extension
phpunit-faker-extension
Using this extension you can use 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.
Installation
You can install this extension by using Composer. This package should be added as a require-dev
dependency:
composer require --dev icanhazstring/phpunit-faker-extension
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
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:
See faker documentation for more information about formatters: https://github.com/fzaninotto/faker#formatters
Running tests with a given seed
To run tests with a given seed, simple set the PHPUNIT_SEED
environment variable before running phpunit:
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:
License
phpunit-faker-extension is available under the MIT License.